I have a small MVC 3 application 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 changes to the model (for example, add a property), I get as expected
The model supporting the JournalContext context has changed since the database was created.
So, while in development mode, I continue and delete Journal.mdf and Journal.ldf.
Now, when I launch the application again, I get
Unable to open the database "MyJournal" requested at login. Login failed.
If I change the connection string to
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Journal.mdf;User Instance=true;Database=MyJournal2
(changed the parameter Database= by adding "2")
The .mdf magazine is created and the application works again. If I make a series of changes and try to “rework” any database name again, I get a “Can't open” message.
Why do I need to provide a unique database name every time I change the model, and how can I “clear” previous names?
source share