Many Visual Studio project-templates configure a SQL Server LocalDB instance for development on your local machine. For example the ASP.NET with Identity template.
But what to do if that database gets corrupted or you need a clean one for testing your Entity Framework Migrations, for example?
One solution is this:
- Open up the Package Manager Console (Tools -> NuGet Package Manager -> Package Manager Console). Make sure to select the project containing your database in the DefaultProject dropdown.
- Enter the command
sqllocaldb info
at the prompt. The result is the name of your SQL Server LocalDB instance. - Enter the command
sqllocaldb stop InstanceName
. Replace “InstanceName” with the name you got from the previous command. - Enter the command
sqllocaldb delete InstanceName
. Replace “InstanceName” as in the command before.Commands to stop and delete the LocalDB database. - Open the folder where the database files (*.mdf) are stored.
Open App-data folder in Windows Explorer - Delete the two *.mdf files in the folder.
Depending on your configuration your database will be re-created automatically when you execute your application or running Update-Database
in the Package Manager Console.
Great… this just destroyed my solution… Local DB was NOT rebuilt after deleting it! How should it?
Hi Alex, sorry for hearing that it did not work out for you. Have you tried running “Update-Database” or something else to have Visual Studio re-create your database? Please comment with a valid email-address next time so you can get any answers on your comment. Just venting your frustration it not very helpful.