I'm doing a code first Entity database
我正在做一个代码第一个实体数据库
{"An exception occurred while initializing the database. See the InnerException for details."}
{“初始化数据库时发生异常。有关详细信息,请参阅InnerException。”}
It was working fine, but I decided to delete the physical database to see it recreate it, but it just fails every time.
它工作正常,但我决定删除物理数据库以查看它重新创建它,但它每次都失败。
I get the error
我收到了错误
Cannot attach the file 'C:\ASP\OdeToFood\OdeToFood\App_Data\OdeToFoodDb.mdf' as database 'OdeToFoodDb'."}
无法将文件'C:\ ASP \ OdeToFood \ OdeToFood \ App_Data \ OdeToFoodDb.mdf'作为数据库'OdeToFoodDb'附加。“}
Its code first so I don't understand why its not recreating the database.
它的代码首先,所以我不明白为什么它不重新创建数据库。
1 个解决方案
#1
14
So deleting the file from Visual Studio was a dumb idea.
因此,从Visual Studio中删除文件是一个愚蠢的想法。
SQL still has it registered.
SQL仍然注册了它。
Fire up MS Sql Management Tool, connect to the server in my case
启动MS Sql管理工具,在我的情况下连接到服务器
(local)\v11.0
(本地)\ V11.0
You will see the database, still exists, delete it, you will get an error. The file doesn't exist. Refresh and its gone from SQL. Now run your code again and all is good.
您将看到数据库仍然存在,删除它,您将收到错误。该文件不存在。刷新并从SQL中消失。现在再次运行你的代码,一切都很好。
So delete the DB from the management tool not visual studio.
所以从管理工具中删除数据库而不是visual studio。
#1
14
So deleting the file from Visual Studio was a dumb idea.
因此,从Visual Studio中删除文件是一个愚蠢的想法。
SQL still has it registered.
SQL仍然注册了它。
Fire up MS Sql Management Tool, connect to the server in my case
启动MS Sql管理工具,在我的情况下连接到服务器
(local)\v11.0
(本地)\ V11.0
You will see the database, still exists, delete it, you will get an error. The file doesn't exist. Refresh and its gone from SQL. Now run your code again and all is good.
您将看到数据库仍然存在,删除它,您将收到错误。该文件不存在。刷新并从SQL中消失。现在再次运行你的代码,一切都很好。
So delete the DB from the management tool not visual studio.
所以从管理工具中删除数据库而不是visual studio。