ASP.Net Linq to Entities:尝试附加自动命名数据库失败
问题是下面错误中显示的数据库路径不正确。我找不到该路径的设置位置,因为它不在设置或任何项目文件中。我错过了什么:
错误:
尝试为文件 H:\FoxCityGuide\FoxCityGuide\App_Data\Restaurants.mdf 附加自动命名数据库失败。
数据库路径:
H:\FoxCityGuide\FoxCityGuide\Restaurants.mdf
app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections></configSections>
<connectionStrings>
<add name="RestaurantsEntities" connectionString="metadata=res://*/Restaurants.csdl|res://*/Restaurants.ssdl|res://*/Restaurants.msl;provider=System.Data.SqlClient;provider connection string="data source=SFP;attachdbfilename=|DataDirectory|\Restaurants.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
The problem is that the path to my database shown in the error below is incorrect. I cannot find where that path is set as it is not in the settings or in any of the project files. What am I missing:
The error:
An attempt to attach an auto-named database for file H:\FoxCityGuide\FoxCityGuide\App_Data\Restaurants.mdf failed.
The path to the database:
H:\FoxCityGuide\FoxCityGuide\Restaurants.mdf
app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections></configSections>
<connectionStrings>
<add name="RestaurantsEntities" connectionString="metadata=res://*/Restaurants.csdl|res://*/Restaurants.ssdl|res://*/Restaurants.msl;provider=System.Data.SqlClient;provider connection string="data source=SFP;attachdbfilename=|DataDirectory|\Restaurants.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有 2 个选项。
将您的 .mdf 文件移至 App_Data 文件夹中,因为 |DataDirectory| 就在该文件夹中指向。
通过编辑配置的“attachdbfilename=”值,更新连接字符串以指向当前位置的 .mdf 文件。
2 options here.
Move your .mdf file into the App_Data folder as that is where |DataDirectory| is pointing.
Update your connection string to point at the .mdf file in its current location by editing the 'attachdbfilename=' value of your config.