Delete localDb database after physical files have been deleted

While working on setting up a new project structure for the team and prototyping how I could get the Entity Framework ‘Update-Database’ command to work from the repository project (EF aware) to create/update the database and have the web project (not EF aware) make use of the database – I made the mistake of deleting the database mdf and ldf files.

Here are the steps I found to resolve the problem.

  1. Open a command prompt
  2. We first need to start the localDb instance if it is not already running.
    Run command: “C:Program FilesMicrosoft SQL Server110ToolsBinnsqllocaldb.exe” start “v11.0”
  3. We need to use the VS2012 sqlcmd tool to do the delete. After running this command it display and error “Unable to open physical file”, “File activation error” but it does delete the references to the database stored by localDb
    Run command “C:Program FilesMicrosoft SQL Server110ToolsBinnsqlcmd” -S (localdb)v11.0 -E -d master -Q “DROP DATABASE [myDatabase]”
  4. Run command: “C:Program FilesMicrosoft SQL Server110ToolsBinnsqllocaldb.exe” stop “v11.0”
  5. Close command prompt

Useful links:
SqlClient Support for LocalDB
Error connecting to localdb after .mdf and .ldf files are deleted.