ASP.Net Linq to Entities:尝试附加自动命名数据库失败

发布于 2024-12-21 22:16:48 字数 945 浏览 2 评论 0原文

问题是下面错误中显示的数据库路径不正确。我找不到该路径的设置位置,因为它不在设置或任何项目文件中。我错过了什么:

错误:

尝试为文件 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=&quot;data source=SFP;attachdbfilename=|DataDirectory|\Restaurants.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

远山浅 2024-12-28 22:16:48

这里有 2 个选项。

  1. 将您的 .mdf 文件移至 App_Data 文件夹中,因为 |DataDirectory| 就在该文件夹中指向。

  2. 通过编辑配置的“attachdbfilename=”值,更新连接字符串以指向当前位置的 .mdf 文件。

2 options here.

  1. Move your .mdf file into the App_Data folder as that is where |DataDirectory| is pointing.

  2. Update your connection string to point at the .mdf file in its current location by editing the 'attachdbfilename=' value of your config.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文