Localdb Attach Problem

在进行code first的迁移时,update-database后默认在App_data文件夹下会新建数据库,如果删除了在使用update-database命令会出现以下错误:

Cannot attach the file ‘E:\WebApiStudy\App_Data\BooksAPIContext-20150419115728.mdf‘ as database ‘BooksAPIContext-20150419115728‘.

原因:虽然.mdf文件被删除了,但是在localdb中的引用还在。

解决方案:

1.在nuget控制台中运行以下命令:

sqllocaldb.exe stop v11.0
     sqllocaldb.exe delete v11.0

其中 v11.0是实例名,来之组连接字符串

<connectionStrings>
    <add name="BooksAPIContext" connectionString="Data Source=(localdb)\v11.0; Initial Catalog=BooksAPIContext-20150419115728; Integrated Security=True; MultipleActiveResultSets=True; AttachDbFilename=|DataDirectory|BooksAPIContext-20150419115728.mdf"
      providerName="System.Data.SqlClient" />
  </connectionStrings>

2.改变连接字符串的名字(生成的数据库的名字是连接字符串的名字)

3.使用sqlserver连上(localdb)\V11.0 实例,删除这个数据库

之后再运行update-database命令就正常了。

原文:Localdb Attach Problem in Visual Studio 2013

时间: 2024-10-08 12:17:23

Localdb Attach Problem的相关文章

Cannot attach the file ‘{0}&#39; as database &#39;{1}&#39;

EF使用CodeFirst,当使用localDB时,删除mdf文件,会报“Cannot attach the file ‘{0}' as database '{1}'”错误. 解决方法如下: 1.打开Visual Studio 命令提示 2.sqllocaldb.exe stop v11.0 3.sqllocaldb.exe delete v11.0 然后重新生成数据库文件即可 Cannot attach the file '{0}' as database '{1}'

We have a problem with promises

原文地址:http://fex.baidu.com/blog/2015/07/we-have-a-problem-with-promises/ 用Javascript的小伙伴们,是时候承认了,关于 promises 我们一直存在着问题.并非说 promises 本身有问题,Promises/A+ 是极好的. 就我过去数年观察大量 PouchDB API 以及其他 promise-heavy API 的使用者们与这些 API 的搏斗中我发现,最大的问题是: 大部分使用 promises 的小伙伴们

Cannot attach the file as database

Cannot attach the file as database这个异常是在EF的code frist里经常出现的,解决方法很简单,只要重新启动一下V11实例即可. CMD> sqllocaldb.exe stop v11.0 LocalDB instance "v11.0" stopped. CMD> CMD> sqllocaldb.exe delete v11.0 LocalDB instance "v11.0" deleted. CMD&

Cannot attach the file &#39;E:\TeamWork\Fido\Fido.WebSite\App_Data\FidoData.mdf&#39; as database &#39;FidoData&#39;.

打开GuGet命令框,输入如下命令就可以了 PM> sqllocaldb.exe stop v11.0 LocalDB instance "v11.0" stopped. PM> PM> sqllocaldb.exe delete v11.0 LocalDB instance "v11.0" deleted. PM> sqllocaldb.exe start v11.0 LocalDB instance "v11.0" s

Failed to Attach to Process ID Xcode 解决办法

方法1. go to the Product menu and find the Edit Scheme menu there. While in Edit Scheme window, select the "Run" option on the left hand side of the screen and then on the right hand side, change the debugger from LLDB to GDB. 方法2. Step1: ping$ pi

【转】We have a problem with promises

这是我看的自认为最好的一篇讲解如何使用Promise的文章,原文地址:http://fex.baidu.com/blog/2015/07/we-have-a-problem-with-promises/ 用Javascript的小伙伴们,是时候承认了,关于 promises 我们一直存在着问题.并非说 promises 本身有问题,Promises/A+ 是极好的. 就我过去数年观察大量 PouchDB API 以及其他 promise-heavy API 的使用者们与这些 API 的搏斗中我发

Cannot attach the file as database &#39;membership&#39;.

Cannot attach the file 'D:\GitHome\cae\CAE\App_Data\membership.mdf' as database 'membership'. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息. 异常详细信息: System.Data.SqlClient.SqlException: Cannot attach the file 'D:\GitHome\cae\CAE\App_

EF架构~Cannot attach the file as database

回到目录 Cannot attach the file as database这个异常是在EF的code frist里经常出现的,解决方法很简单,只要重新启动一下V11实例即可. CMD> sqllocaldb.exe stop v11.0 LocalDB instance "v11.0" stopped. CMD> CMD> sqllocaldb.exe delete v11.0 LocalDB instance "v11.0" deleted.

异常处理:Cannot attach the file as database &#39;membership&#39;.

Cannot attach the file 'D:\GitHome\cae\CAE\App_Data\membership.mdf' as database 'membership'. 说明: 执行当前 Web 请求期间,出现未经处理的异常.请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息. 异常详细信息: System.Data.SqlClient.SqlException: Cannot attach the file 'D:\GitHome\cae\CAE\App_