问题描述
基本上,我按照教程,决定删除 .mdf
文件。
Basically I've followed a tutorial and decided to delete the .mdf
file afterwards.
我试图运行应用程序我得到以下错误(这个线程的标题)。
我得到错误的代码如下所示(ASP.NET MVC 4):
Now whenever I try to run the application I get the following error (the title of this thread).The code where I get the error is shown below (ASP.NET MVC 4):
OdeToFoodDB db = new OdeToFoodDB();
public ActionResult Index()
{
var model = db.Restaurants.ToList();
return View(model);
}
我的连接字符串如下:
<add name="DefaultConnection"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=OdeToFoodDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\OdeToFoodDb.mdf"
providerName="System.Data.SqlClient" />
我试过查看SQL Server对象资源管理器,但它看起来如下:
I've tried looking at the SQL Server Object Explorer but it looks the following:
此外,在服务器资源管理器中,我没有看到任何数据连接。
Also, in Server Explorer I don't see any data connections.
当我尝试添加一个新的连接服务器资源管理器我没有看到任何名为 OdeToFoodDb
的数据库。
And when I try to add a new connection in Server Explorer I don't see any databases named OdeToFoodDb
.
对于这个广泛的问题,到实体框架,这里不会有什么问题。
Sorry for this wide question but I'm new to Entity Framework and don't quite get what's wrong here.
推荐答案
看看这个:
编辑
此回答已被接受,因为它确认了错误和OP使用的解决方法(重命名数据库可以帮助)。我完全同意重命名数据库不是真正可以接受的方式,不能完全解决问题。不幸的是,我没有检查其他方法来真正解决它在SSMS。
EditThis answer was accepted because it confirms the bug and the workaround used by OP (renaming database could help). I totally agree that renaming the database is not really an acceptable way, and does not totally solve the issue. Unfortunatly I didn't check the other ways to really solve it in SSMS.
这篇关于无法将文件* .mdf附加为数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!