How To Upgrade Visual Studio’s LocalDB to the latest version
Updated for 2024.
If you’re like me and you always want to be on the latest and greatest, you’d be surprised that the latest and greatest version of SQL Server installed with VS2019 is at least two major versions behind the currently-shipping version… and VS2022’s version is now one major release behind.
It’s not very difficult to upgrade manually, but there are a couple steps. Follow them carefully, and you’ll be up and running in no time. Oh, and these steps work for SQL Server 2017 LocalDB too (if you’re still stuck on that for some reason)😉.
Step 1: Upgrade the LocalDB bits
You can grab the latest installers here:
When you run it, it will first download the installation files to C:\SQL2022 (or C:\SQL2019), then it will execute the SQL Installer.
NOTE (16 March 2024): I originally wrote this for SQL 2019. The installer UI has not changed since then (except for the product name), so I’m not going to update the screenshots for now.
Select “Upgrade from a previous version of SQL Server”. It should take you to the “Upgrade to SQL Server 2019” wizard.
Roll through the process until you get to the “Select Features” phase. NOTE: There appears to be a bug on this page of the UI that start the upgrade no matter what you click… so don’t click anywhere in the window unless you are sure you want to proceed.
This will take a few minutes to complete. After it’s done, you might want to restart your computer.
Step 2: Rebuild the LocalDB instance
For reasons beyond my understanding, the upgrade process doesn’t actually upgrade the code itself… any current instances on your machine will still be leveraging the old code. In order to solve this problem, you must blow away your old instances and re-attach the databases.
Open a Powershell window and run the following commands:
sqllocaldb stop projectsv13
sqllocaldb delete projectsv13
sqllocaldb stop mssqllocaldb
sqllocaldb delete mssqllocaldb
sqllocaldb create MSSQLLocalDB
At this point you have a clean instance. One more step to go.
Step 3: Reattach your databases
The LocalDB databases and their log files are usually stored in the %UserProfile%
folder. You’ll want to check and make sure there are there before you continue.
You should at this point be able to open Visual Studio, and hit Ctrl+\, Ctrl+S to open the SQL Server Object Explorer view.
Click the icon with the green “plus”, and the Connect screen will come up. (Note: At some point, VS will re-add the “ProjectsV13" instance, probably during monthly updates. Ignore it for now.)
Select “MSSQLLocalDB” and click “Connect”. You should see it show up under “SQL Server” in the SQL Server Object Explorer.
Right-click that instance and select “New Query” to open a new Query window in Visual Studio. Then paste in the query below:
CREATE DATABASE {YOURDATABASENAME}
ON (FILENAME = '{DATABASEPATH}\{YOURDATABASENAME}.mdf'),
(FILENAME = '{DATABASEPATH}\{YOURDATABASENAME}.ldf')
FOR ATTACH;
Make sure you substitute {DATABASEPATH}
for the location of the database, and {YOURDATABASENAME}
for every database you’re re-attaching.
In Closing
It’s unfortunate that this process is not more automatic. Microsoft could do a lot more work here than they have to just make it magical. In the absence of that, maybe someone can whip up a script at some point to make it easier. In the meantime, I hope this helps 👊🏻.