Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a LocalDB instance completely?

I am using SQL Server 2014 Express and Visual Studio Community 2015.

When I used sqllocaldb i to list all localdb instances in my PC, I can see 2 instances, e.g. MSSQLLocalDB and ProjectsV12. I can stop and delete an instance by using sqllocaldb stop MSSQLLocalDB and sqllocaldb delete MSSQLLocalDB.

Then I deleted the folder MSSQLLocalDB under AppData\Local\Microsoft\Microsoft SQL Server Local DB\Instances\, but when I run sqllocaldb i again, both localdb instances still exist. The problem is that when I launch VS2015, the deleted folder will be re-generated!

How can I delete the localdb instance from my PC completely?

like image 262
Richie Avatar asked Oct 31 '22 22:10

Richie


1 Answers

After you delete the instances like you have done with sqllocaldb, check if the auto-generated .mdf file in the project that uses the localdb still has that file in the folder App_Data and also make sure that you delete the correct database in the Server Explorer, i.e.:

  1. Find in Web.Config the <connectionStrings> tag and check under AttachDBFilename property which file is being generated (you can also alter the name of the file in here and in order to change it's name completely, you can modify the Data Source=(LocalDb)\ProjectsV12 field);
  2. Go to the Solution Explorer (Ctrl+W+S);
  3. Click on App_Data folder and in the top bar of the Solution Explorer click the Show All Files icon and then on the Refresh icon;
  4. Delete the .mdf file in that folder;
  5. Go to the Server Explorer (Ctrl+W+L);
  6. Under Data Connections delete the matching database;
  7. After this in command line use sqllocaldb delete ProjectsV12 to make sure it's definitely deleted;
  8. Update-Database in the Package Manager Console to regenerate the database (or the new instance, as you redefined in Web.Config).
like image 140
CPHPython Avatar answered Nov 08 '22 03:11

CPHPython