Skip to main content

SqlLocalDB command line tool

A few years ago, Microsoft created SQL Server LocalDB,  an execution mode of SQL Server Express targeted to developers. LocalDB installation copies a minimal set of files necessary to start the SQL Server Database Engine making it much easier to install and manage. Once LocalDB is installed, developers initiate a connection by using a special connection string:
Data Source=(LocalDB)\MyInstance;Initial Catalog=foo;Integrated Security=True;
When connecting, the necessary SQL Server infrastructure is automatically created and started, enabling the application to use the database without complex or time consuming configuration tasks. An instance of SQL Server Express LocalDB is managed by using the SqlLocalDB.exe utility.
LocalDB supports two kinds of instances: Automatic instances and named instances.
From MSDN:
  • Automatic instances of LocalDB are public. They are created and managed automatically for the user and can be used by any application. One automatic instance of LocalDB exists for every version of LocalDB installed on the user’s computer. Automatic instances of LocalDB provide seamless instance management. There is no need to create the instance; it just works. This allows for easy application installation and migration to a different computer. If the target machine has the specified version of LocalDB installed, the automatic instance of LocalDB for that version is available on the target machine as well. Automatic instances of LocalDB have a special pattern for the instance name that belongs to a reserved namespace. This prevents name conflicts with named instances of LocalDB. The name for the automatic instance is MSSQLLocalDB.
  • Named instances of LocalDB are private. They are owned by a single application that is responsible for creating and managing the instance. Named instances provide isolation from other instances and can improve performance by reducing resource contention with other database users. Named instances must be created explicitly by the user through the LocalDB management API or implicitly via the app.config file for a managed application (although managed application may also use the API, if desired). Each named instance of LocalDB has an associated LocalDB version that points to the respective set of LocalDB binaries. The instance name of a LocalDB is sysname data type and can have up to 128 characters. (This differs from regular named instances of SQL Server, which limits names to regular NetBIOS names of 16 ASCII chars.) The name of an instance of LocalDB can contain any Unicode characters that are legal within a filename. A named instance that uses an automatic instance name becomes an automatic instance.

To connect to an automatic instance, you can use the following connection string:
Server=(localdb)\MSSQLLocalDB;Integrated Security=true
To connect to a namend instance, you first need to use the SqlLocalDB.exe command line tool to create and start a named instance of LocalDB:
REM Create an instance of LocalDB  
SqlLocalDB create MyInstance
REM Start the instance of LocalDB  
SqlLocalDB start MyInstance
REM Gather information about the instance of LocalDB  
SqlLocalDB info MyInstance
Once created you can use the following connection string:
Data Source=(localdb)\MyInstance;Initial Catalog=foo;Integrated Security=True;
UPDATE: If you are using a SQL Server version below 2014, the connectionstring for the automatic instance is/was:

Server=(localdb)\v11.0;Integrated Security=true

Popular posts from this blog

DevToys–A swiss army knife for developers

As a developer there are a lot of small tasks you need to do as part of your coding, debugging and testing activities.  DevToys is an offline windows app that tries to help you with these tasks. Instead of using different websites you get a fully offline experience offering help for a large list of tasks. Many tools are available. Here is the current list: Converters JSON <> YAML Timestamp Number Base Cron Parser Encoders / Decoders HTML URL Base64 Text & Image GZip JWT Decoder Formatters JSON SQL XML Generators Hash (MD5, SHA1, SHA256, SHA512) UUID 1 and 4 Lorem Ipsum Checksum Text Escape / Unescape Inspector & Case Converter Regex Tester Text Comparer XML Validator Markdown Preview Graphic Color B

Help! I accidently enabled HSTS–on localhost

I ran into an issue after accidently enabling HSTS for a website on localhost. This was not an issue for the original website that was running in IIS and had a certificate configured. But when I tried to run an Angular app a little bit later on http://localhost:4200 the browser redirected me immediately to https://localhost . Whoops! That was not what I wanted in this case. To fix it, you need to go the network settings of your browser, there are available at: chrome://net-internals/#hsts edge://net-internals/#hsts brave://net-internals/#hsts Enter ‘localhost’ in the domain textbox under the Delete domain security policies section and hit Delete . That should do the trick…

Azure DevOps/ GitHub emoji

I’m really bad at remembering emoji’s. So here is cheat sheet with all emoji’s that can be used in tools that support the github emoji markdown markup: All credits go to rcaviers who created this list.