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
Localdb Attach Problem的更多相关文章
- UBI FAQ and HOWTO
转:http://www.linux-mtd.infradead.org/faq/ubi.html UBI FAQ and HOWTO Table of contents How do I enabl ...
- Cannot attach the file ‘{0}' as database '{1}'
EF使用CodeFirst,当使用localDB时,删除mdf文件,会报“Cannot attach the file ‘{0}' as database '{1}'”错误. 解决方法如下: 1.打开 ...
- EF with (LocalDb)V11.0
EF虽说对LocalDb支持的不错,但LocalDb有自身的缺陷(不想sqlite那样数据库文件可以像普通文件一样使用). LocalDb在一个计算机上会对数据库有唯一性约束,要求本机的localdb ...
- We have a problem with promises
原文地址:http://fex.baidu.com/blog/2015/07/we-have-a-problem-with-promises/ 用Javascript的小伙伴们,是时候承认了,关于 p ...
- EF架构~Cannot attach the file as database
回到目录 Cannot attach the file as database这个异常是在EF的code frist里经常出现的,解决方法很简单,只要重新启动一下V11实例即可. CMD> sq ...
- Cannot attach the file as database 'membership'.
Cannot attach the file 'D:\GitHome\cae\CAE\App_Data\membership.mdf' as database 'membership'. 说明: 执行 ...
- Cannot attach the file as database
Cannot attach the file as database这个异常是在EF的code frist里经常出现的,解决方法很简单,只要重新启动一下V11实例即可. CMD> sqlloca ...
- 还原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 ...
- Bender Problem
Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n ...
随机推荐
- WebBrowser.ExecWB方法
<html> <head> <meta http-equiv="Content-Type" content="text/html; char ...
- jQuery Scroll div滚动条样式更改
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script> ...
- 手机网页中的hover效果实现
js文件 function mouseout(obj) { var className ="hover"; var _ecname = obj.className; if (_ec ...
- 转载:spring ,struct2 在 web.xml中的配置
转载网址:http://blog.sina.com.cn/s/blog_4c6e822d0102dv63.html <!-- Struts2 need begin--> <filt ...
- MySQL Left Join,Right Join
魂屁,东西发这里了关于Left Join,Right Join的 在讲MySQL的Join语法前还是先回顾一下联结的语法,呵呵,其实连我自己都忘得差不多了,那就大家一起温习吧(如果内容有错误或有疑问, ...
- HTML&CSS基础学习笔记1.23-表单的文本域和下拉列表
文本域 <textarea>标签定义多行的文本输入控件. 平时在网页上的一些需要输入比较多的内容的输入框,比如回复帖子,回答问题等,都可以用<textarea>标签. < ...
- 关于把A表中的数据复制到B表中。
最近公司需要把sql中的数据给整理出来,这就牵涉到数据转移问题. 我平时是很少接触sql这一块的.所以碰到这个问题甚是伤脑筋. 不过还好,这问题并不像我想象中的那么的困难. 以前做过把数据插入到临时表 ...
- C语言中如何获得文件大小
方法一: 获得文件大小需要用到2个函数:fseek() , ftell() fseek()函数: 原型:intfseek(FILE *stream, long offset, int fromwher ...
- cf B. Permutation
#include <cstdio> #include <cstring> #include <algorithm> using namespace std; ]; ...
- cf C. Dima and Containers
http://codeforces.com/contest/358/problem/C 将最大的放在stack里面,第二大的放在queue中,第三大的放在deck里面.然后模拟就可以了. #inclu ...