Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

context.Database.Exists always returns true, even if database file is missing

If I create a new MVC4 Web Application with the Internet Application project template (which uses forms authentication) then, when I run it the first time and click on Register, the call to context.Database.Exists (in the InitializeSimpleMembershipAttribute filter) correctly detects that the database file does not exist, and ObjectContext.CreateDatabase is called, creating the dbf and ldf files in the App_Data folder.

If I then delete the dbf and ldf files and run the app again, the call to context.Database.Exists returns true, despite the fact that the database file is gone. This behavior seems to be persistent: Once ObjectContext.CreateDatabase has been called, some magic seems to remember that the database "exists", even if the physical file is gone and even if I restart the PC.

Ok, so I assume that something in SQL Server is remembering the existence of the database. So I've installed and run SQL Server Management Studio. But the only thing that appears under the Databases folder under the \SQLEXPRESS node is the System Databases folder. I see no sign of my database file connection.

What's this all about? Why does context.Database.Exist return true, and how can I convince it to return false if the database file is gone? And why don't I see some evidence of the database connection in SQL Server Management Studio?

Bob

like image 592
Bob.at.Indigo.Health Avatar asked Oct 06 '22 00:10

Bob.at.Indigo.Health


1 Answers

You can remove the database by deleting it from your LocalDb instance. Using SQL Managment Studio connect to "(LocalDb)\v11.0".

like image 131
ckal Avatar answered Oct 13 '22 10:10

ckal