An exception occurred while initializing the database

asp.net asp.net-mvc entity-framework

Question

I'm doing a code first Entity database

{"An exception occurred while initializing the database. See the InnerException for details."}

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'."}

Its code first so I don't understand why its not recreating the database.

1
10
5/5/2013 4:31:04 AM

Accepted Answer

So deleting the file from Visual Studio was a dumb idea.

SQL still has it registered.

Fire up MS Sql Management Tool, connect to the server in my case

(local)\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.

So delete the DB from the management tool not visual studio.

14
5/5/2013 5:02:05 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow