无法附加文件* .MDF数据库 [英] Cannot attach the file *.mdf as database

查看:232
本文介绍了无法附加文件* .MDF数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上,我跟着一个教程,并决定以后删除 .MDF 文件。

Basically I've followed a tutorial and decided to delete the .mdf file afterwards.

现在,每当我尝试运行我得到以下错误(这个帖子的标题)的应用程序。 在code,我得到的错误如下所示(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);
}

我的连接字符串如下:

My connection string is the following:

<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.

推荐答案

看看这个:实体框架别'T创建数据库

我会尝试给数据库   不同的名称。有时你会遇到的问题与SQL防爆preSS   当试图创建具有相同名称的第二次的数据库。   有一种方法来解决这个问题使用SQL Server Management Studio,但它的   通常更简便的使用不同的数据库名。

I would try giving the database a different name. Sometimes you can run into problems with SQL Express when trying to create a database with the same name a second time. There is a way to fix this using SQL Server Management Studio but it's generally easier to just use a different database name.

这篇关于无法附加文件* .MDF数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆