在进行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. (转)C# DateTime格式化大全

    //c datetime 格式化 DateTime dt = DateTime.Now; Label1.Text = dt.ToString();//2005-11-5 13:21:25 Label2 ...

  2. 工厂方法模式(java 设计模式)

    1.工厂方法模式的定义 工厂方法模式使用的频率非常高, 在我们日常的开发中总能见到它的身影. 其定义为:Define an interface for creating an object,but l ...

  3. RecycleView 瀑布流滑动移位

    RecycleView StaggeredLayoutManager(瀑布流)滑动的时候,默认会出现item移动的问题,需以下来个步骤来解决: 附上StaggeredLayoutManager中的一段 ...

  4. PagerSlidingTabStrip的使用

    布局 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:too ...

  5. MS SQL到Oracle的数据迁移笔记

    MS SQL到Oracle的数据迁移笔记 一.任务背景 旧系统使用MS SQL Server数据库,新系统使用Oracle数据库,现在需要将旧系统中的数据迁移到新系统中,旧数据按照约定的规则转换后,能 ...

  6. cocos2dx Sprite的多种创建方法

    1.通过文件创建 Sprite *bg = Sprite::create("backGround.jpg"); 2.通过图片的某个区域创建 SpriteFrame *frame = ...

  7. 带权并查集 poj1182

    首先要注意核心代码 int find(int i){    if(i == fa[i])        return fa[i];    int tt = find(fa[i]);    num[i] ...

  8. 网络流初步——增广路算法(EK)模板

    #include <iostream> #include <queue> #include<string.h> using namespace std; #defi ...

  9. shell中的path expansion

    glob扩展 在shell中的路径扩展中,涉及到的glob有如下几种: ? 匹配任何单个字符 * 匹配0到多个字符 [set] 匹配任何一个在set当中的字符,如[0-9],则匹配任何一个数字 [!s ...

  10. Objective-C 静态变量 使用方法

    详解Objective-C中静态变量使用方法 Objective-C中静态变量使用方法是本文要介绍的内容,Objective-C 支持全局变量,主要有两种实现方式:第一种和C/C++中的一样,使用&q ...