I'm using VS 2013 and EF6.1 for my job.
Whenever I deal with migration and destroy databases, I encounter a same error.
I couldn't make the database again.
The local SQLExpress database instance that was causing the problem was running in the background and still using the connection to the deleted database.
The steps to handle this scenario are shown below.
- The database files (.mdf and.ldf) should be deleted.
- Migration Folder should be removed from your application.
- Delete all instances of that database's connections from server Explorer's data connections.
- Activate the Windows Command Prompt (IF VS 2012 or earlier you have to use the VS Command prompt).
- Activate "sqllocaldb.exe stop v11.0" (This will stop the v11.0 service)
- Run the SQLlocalDB.EXE delete v11.0 command (This will delete the v11.0 service)
- open Visual Studio's Package Manager Console.
- Run the migrations command (This will create Migration folder and content)
- Activate "Add-Migration init" (This will scaffold the changes to next migration)
- Activate "Update-Database" (This will create the database again)