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

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.

Kubernetes–Limit your environmental impact

Reducing the carbon footprint and CO2 emission of our (cloud) workloads, is a responsibility of all of us. If you are running a Kubernetes cluster, have a look at Kube-Green . kube-green is a simple Kubernetes operator that automatically shuts down (some of) your pods when you don't need them. A single pod produces about 11 Kg CO2eq per year( here the calculation). Reason enough to give it a try! Installing kube-green in your cluster The easiest way to install the operator in your cluster is through kubectl. We first need to install a cert-manager: kubectl apply -f https://github.com/cert-manager/cert-manager/releases/download/v1.14.5/cert-manager.yaml Remark: Wait a minute before you continue as it can take some time before the cert-manager is up & running inside your cluster. Now we can install the kube-green operator: kubectl apply -f https://github.com/kube-green/kube-green/releases/latest/download/kube-green.yaml Now in the namespace where we want t

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