5

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

3
  • 2
    Can it be that you are not looking at the right database? Is it VS 2012? If so, It might be (localdb)\v11.0 instead .\SqlExpress. context.Database.Connection.ConnectionString will tell you the truth. Commented Nov 14, 2012 at 4:58
  • If you do Database.Delete and Database.Create are the files back again in the App_Data folder? Commented Nov 14, 2012 at 21:14
  • Yes, it is (localdb), not SQLEXPRESS. That answers part of the mystery. So, can I use something like SQL Studio to examine and/or clean up the dangling database reference, or do I need to write code (Database.Delete)? Commented Nov 15, 2012 at 3:22

1 Answer 1

4

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

Sign up to request clarification or add additional context in comments.

1 Comment

This does not work for me. I deleted the database but Context.Database.Exists returns always true, once it was created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.