从app_data文件删除.mdf文件会导致异常不能附加文件数据库 [英] Delete .mdf file from app_data causes exception cannot attach the file as database

查看:477
本文介绍了从app_data文件删除.mdf文件会导致异常不能附加文件数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立使用VS 2012 MVC4 code第一个Web应用程序。为了以后,我改变了模型来重新创建密度纤维板文件,我手动从在VS的App_Data目录删除的文件我曾经做过这样一个前几次没有任何问题。

I am building a web application using VS 2012 MVC4 code first. In order to recreate the .mdf file after I changed the model, I manually deleted the file from the app_data directory in VS. I have done this a few times before without any problem.

现在我收到一个异常:

基础提供开放式失败。 ==>无法附加文件
   MYDB.mdf 数据库'MYDB'

The underlying provider failed on Open. ==> Cannot attach the file MYDB.mdf as database 'MYDB'.

我将AP preciate你对如何重现密度纤维板文件的帮助。

I will appreciate your help on how to recreate the .mdf file.

感谢您!

推荐答案

使用SQL Server对象资源管理器删除数据库,而不是仅仅删除Solution Explorer中的.mdf文件。否则,S​​QL Server实例仍然认为数据库名称使用,下一次您尝试将数据库附加到它不会工作相同的名称。查看初始目录一节这个MSDN网页:

Use SQL Server Object Explorer to delete the database rather than just deleting the .mdf file in Solution Explorer. Otherwise the SQL Server instance still thinks the database name is used and the next time you try to attach a database to the same name it won't work. See the section on Initial Catalog in this MSDN page:

<一个href=\"http://msdn.microsoft.com/en-us/library/jj653752.aspx#initialcatalog\">http://msdn.microsoft.com/en-us/library/jj653752.aspx#initialcatalog

这篇关于从app_data文件删除.mdf文件会导致异常不能附加文件数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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