从 ASP.NET Razor 中站点的子目录连接到 .sdf 数据库
我正在使用 ASP.NET 网页 Razor 语法构建一个小型网站。它在 App_Data 文件夹中有一个 SQL CE 4 数据库。在根目录和 /Account 子目录中的页面中,连接和从数据库获取记录工作正常。但是,当尝试从其他子目录中的页面中的数据库获取数据时,与数据库的连接不起作用。我收到错误:未找到连接字符串“Database.sdf”。
它使用根目录中 Web.config 文件中的连接字符串:
当我尝试将根 Web.config 复制到子目录时,出现以下错误:
条目“数据库”已被添加。 (C:\Users\Name\Documents\Visual Studio 2010\WebSites\SmallWebsite\subdir\web.config 第 11 行)。
目前我很困惑,似乎无法在 msdn 或 google 中找到答案。非常感谢任何帮助。
谢谢 NL
I have a small website that I am building using ASP.NET web pages Razor Syntax. It has an SQL CE 4 database in the App_Data folder. The connection and getting records from the database works fine in pages that are in the root directory and the /Account subdirectory. However when trying to get data from the database in pages that are in other subdirectories, connection to the database does not work. I get an error: Connection string "Database.sdf" was not found.
It is using the connection string from the Web.config file in the root directory:
When I tried copying the root Web.config to the subdirectory I get the following error:
The entry 'Database' has already been added. (C:\Users\Name\Documents\Visual Studio 2010\WebSites\SmallWebsite\subdir\web.config line 11).
At the moment I'm stumped and can't seem to find an answer either in msdn or google. Any help greatly appreciated.
Thanks
nl
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
解决了!事实证明我所需要做的就是阅读错误消息。在根页面中,我使用代码:
var db = Database.Open("Database");连接,并在子目录中:
var db = Database.Open("Database.sdf");
一旦我删除了.sdf,一切就正常了!
谢谢,
NL
Solved! Turns out all I needed to do was actually read the error message. In the root pages I was using code:
var db = Database.Open("Database"); to connect, and in subdirectories:
var db = Database.Open("Database.sdf");
Once I removed the .sdf everything worked fine!
Thanks,
nl