在进行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

Localdb Attach Problem的更多相关文章

  1. UBI FAQ and HOWTO

    转:http://www.linux-mtd.infradead.org/faq/ubi.html UBI FAQ and HOWTO Table of contents How do I enabl ...

  2. Cannot attach the file ‘{0}' as database '{1}'

    EF使用CodeFirst,当使用localDB时,删除mdf文件,会报“Cannot attach the file ‘{0}' as database '{1}'”错误. 解决方法如下: 1.打开 ...

  3. EF with (LocalDb)V11.0

    EF虽说对LocalDb支持的不错,但LocalDb有自身的缺陷(不想sqlite那样数据库文件可以像普通文件一样使用). LocalDb在一个计算机上会对数据库有唯一性约束,要求本机的localdb ...

  4. We have a problem with promises

    原文地址:http://fex.baidu.com/blog/2015/07/we-have-a-problem-with-promises/ 用Javascript的小伙伴们,是时候承认了,关于 p ...

  5. EF架构~Cannot attach the file as database

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

  6. Cannot attach the file as database 'membership'.

    Cannot attach the file 'D:\GitHome\cae\CAE\App_Data\membership.mdf' as database 'membership'. 说明: 执行 ...

  7. Cannot attach the file as database

    Cannot attach the file as database这个异常是在EF的code frist里经常出现的,解决方法很简单,只要重新启动一下V11实例即可. CMD> sqlloca ...

  8. 还原bak到localdb的问题:The logical database file cannot be found ldf

    主要环境相关因素:win7,ms sql 2012,ms localdb,msms 2012. 步骤: 1,让DBA给一个bak文件到本地来做测试,DBA按自己的工作流程得到bak文件. 2,在msm ...

  9. Bender Problem

    Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n ...

随机推荐

  1. 报错:/BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3512.29.5/UITableView.m:7943解决方法

    环境:Xcode7.1.1 详细错误: *** Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:], ...

  2. java下文件遍历,与删除

    package cn.stat.p1.file; import java.io.File; public class newfilelist { /** * @param args */ public ...

  3. Flex布局摆脱float带来的布局问题

    完整文章地址http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html?utm_source=tuicool 使用浮动(float)的一个比较疑惑 ...

  4. Struts2 的国际化实现

    以前一直看见 i18N ,现在才知道原来 i18N 就是 Internationalization,因为以 i 开头,以 N 结尾,共18个字母,也就是国际化的意思.在百度搜索主页上没有看见中英文的切 ...

  5. java部分基础总结

    新手期一些知识的总结面向对象: 首先先将面向对象与面向过程区分开:面向过程主要是通过过程,达到某种目的,这种目的的目标就是对象,二面向对象重点则是不再考虑过程,直接面向对象! 对象 概念:一切客观存在 ...

  6. Java中int和String互相转换的多种方法

    1 如何将字串 String 转换成整数 int? A. 有两个方法: 1). int i = Integer.parseInt([String]); 或 i = Integer.parseInt([ ...

  7. 判断Python输入是否为数字

    在接收raw_input方法后,判断接收到的字符串是否为数字 例如: str = raw_input("please input the number:") if str.isdi ...

  8. scala 入门(1)

    大数据“火”的有段日子了,原来打算学习hadoop…… 后知道spark要比hadoop更牛, 故而转学spark.其原码为scala所写,为了更好的研究spark,故又开始学习scala. 将自己所 ...

  9. 转发细节——forward

    1)forward()方法之前的输出,如果是输出到缓冲区,再转发到其它Servlet,那么原缓冲区的数据忽略不计:2)forward()方法之前的输出,如果真正输出到浏览器,再转发到其它Servlet ...

  10. Unity中Mecanim工作流

    Mecanim工作流可以被分解为3个主要阶段:1.资源的准备和导入这一阶段由美术师或动画师通过第三方工具来完成,例如Max或Maya.2.角色的建立主要有以下两种方式1)人形角色的建立.Mecanim ...