Connection Strings for LocalDBdevelopment
Connection Strings for LocalDB
Motivation - Why LocalDB
While watching a course on Pluralsight and coding along I found myself needing a database that Entity Framework could connect to. My DbContext class had a DropCreateDatabaseIfModelChanges method and some test data to store but since I hadn’t re-installed MS SQL Express since doing some maintenance on my PC I didn’t have a database I could immediately connect to.
Not wanting to lose momentum on the course I looked for a quicker option which turned out to be MS SQL Server LocalDB. Knowing that the 2016 version of SQL Server was just release a few weeks ago I decided to go find the download link for LocalDB 2016. Unfortunately it doesn’t exist yet and the SQL Server Express 2016 download page only links to the full installer at the moment.
I downloaded the installer hoping I could just install LocalDB but I did not see any options so I abandoned this approach for the time being.
Fortunately the 2014 installer page provides a modal upon clicking Download that gives a select of options to determine exactly which combination or individual tools to download.
I downloaded the x64 LocalDB installer and ended up repairing the install because I apparently already had LocalDB installed.
I knew the data source should look something like
localdb\someInstance but I wasn’t exactly sure.
I found this page which describes how to work with LocalDB which confirmed my suspicions but I still didn’t know what my instance name was and all the ones I was trying were throwing errors.
I then did some more searching and found a reference to using the SqlLocalDB.exe application as a command line tool to tell me what instances I had available and ensure those instances were online.
I opened up PowerShell and navigated to
C:\Program Files\Microsoft SQL Server\ where I had a couple version options available. I went with the highest one (
130) and navigated to
PS C:\Program Files\Microsoft SQL Server\130\Tools\Binn
In this folder is the
.\SqlLocalDB.exe application which, if entered by itself, will list the command line options that are available. I ran the following commands.
PS C:\Program Files\Microsoft SQL Server\130\Tools\Binn .\SqlLocalDB.exe i
PS C:\Program Files\Microsoft SQL Server\130\Tools\Binn .\SqlLocalDB.exe v
Microsoft SQL Server 2014 (12.0.2000.8)
Microsoft SQL Server 2016 Release Candidate 0 (RC0) (13.0.1100.286)
PS C:\Program Files\Microsoft SQL Server\130\Tools\Binn .\SqlLocalDB.exe start "MSSQLLocalDB"
LocalDB instance "MSSQLLocalDB" started.
PS C:\Program Files\Microsoft SQL Server\130\Tools\Binn</pre>
With the following being the explanations for the options
start|s ["instance name"]Starts the LocalDB instance with the specified name
info|iLists all existing LocalDB instances owned by the current user and all shared LocalDB instances.
info|i "instance name"Prints the information about the specified LocalDB instance.
versions|vLists all LocalDB versions installed on the computer.
So at this point I knew that my instance name was
MSSQLLocalDB, it was started and running and I should be able to connect to it via
I opened up LINQPad and added a new database connection, put in the above data source and everything worked! A few minutes later my demo code was up and running.