I have a small MVC 3 app using Entity Framework Code First and use this connection string for the model:
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Journal.mdf;User Instance=true;Database=MyJournal
When I make a change to the model (e.g. add a property), I get as expected
The model backing the 'JournalContext' context has changed since the database was created.
So, being in development mode, I go ahead and delete Journal.mdf and Journal.ldf.
Now when I run the application again, I get
Cannot open database "MyJournal" requested by the login. The login failed.
If I change my connection string to
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Journal.mdf;User Instance=true;Database=MyJournal2
(changed the Database= parameter by appending '2')
Journal.mdf is created and the app works again. If I make a number of changes and attempt to "recycle" any Database name again, I get the "Cannot open" error.
Why do I need to provide a unique Database name each time I change the model, and how can I "clean out" previous names?