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. - Open the folder where the database files (*.mdf) are stored.
- 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.