Questions tagged [localdb]

LocalDB is a lightweight deployment option for SQL Server Express Edition with the same features but with a simple installation. To support scenarios where multiple users of the computer need to connect to a single instance of LocalDB, LocalDB supports instance sharing but does not support sharing among multiple computers.

SQL Server Express LocalDB, introduced in SQL Server 2012, is a light-weight version of SQL Server Express that replaces User Instances, which were introduced in SQL Server 2005. LocalDB (as it is commonly referred to) instances are created per user, and the instance and their databases are by default installed into a user's local profile directory. (It's possible to save the database file elsewhere, including on a server share). By default these instance are private, but they can be shared with other users on the same computer.

LocalDB runs as a background process for each user that starts their own private instance rather than as a service that is shared by all users and would have its own security context. Connectivity is only through Named Pipes; external connectivity is not available. However, specifying the correct named pipe to connect to can be problematic due to the instance name changing each time it starts (i.e. instance name = LOCALDB#{8_character_alphanumeric_id}, named pipe = np:\\.\pipe\LOCALDB#{8_character_alphanumeric_id}\tsql\query).

Fortunately, a new special syntax for the Server Name was added to use in connection strings. You can specify (localdb)\InstanceName in SSMS, SQLCMD, and via the SqlConnection class in .NET applications (though be aware that this was not available until .NET Framework version 4.0.2). This syntax provides two benefits:

  1. It allows for using a consistent server name in your code
  2. It will automatically start the LocalDB instance if it is not already running.

LocalDB can be started, stopped, and otherwise managed via the SQLLocalDB.exe utility. Additionally, LocalDB will be automatically started when using the (LocalDB)\InstanceName connection string syntax, and it will automatically stop about 5 minutes after the last connection closes.

The easiest way to use LocalDB is to connect to the automatic instance owned by the current user by using the connection string "Server=(localdb)\MSSQLLocalDB;Integrated Security=true". To connect to a specific database by using the file name, connect using a connection string similar to "Server=(LocalDB)\MSSQLLocalDB; Integrated Security=true ;AttachDbFileName=D:\Data\MyDB1.mdf".

To connect to a shared instance of LocalDB add .\ (dot + backslash) to the connection string to reference the namespace reserved for shared instances. For example, to connect to a shared instance of LocalDB named AppData use a connection string such as (localdb)\.\AppData as part of the connection string. A user connecting to a shared instance of LocalDB that they do not own must have a Windows Authentication or SQL Server Authentication login.

For more info, please see:

1023 questions
51
votes
3 answers

SQL Server Express localdb.msi offline installer

I am not able to install using the online installer. Can anyone point me to where I can find the offline installer? I tried searching with Google gut with no luck. This is similar but not an offline installer. How to install localdb separately? This…
Rahul
  • 10,830
  • 4
  • 53
  • 88
45
votes
9 answers

How to transfer ASP.NET MVC Database from LocalDb to SQL Server?

I created a new ASP.NET MVC 5 project in Visual Studio 2013 (Express for Web) and by default, the project uses LocalDb as its database, but how do you transfer or migrate the database to SQL Server? I want to use SQL Server for the database instead…
doncadavona
  • 7,162
  • 9
  • 41
  • 54
43
votes
4 answers

How to manually create a mdf file for localdb to use?

I'm setting up some unit tests for testing work done with a database. I would like to use localdb v11 but first I need to create the database. How exactly do I do this? simply connecting to (localdb)v11 in sql management studio connects me to the…
George Mauer
  • 117,483
  • 131
  • 382
  • 612
41
votes
1 answer

SQL Server Express vs express localdb

I am having quite a few problems understanding differences between regular SQL Server Express and express Localdb. Before you go ahead and tag a previous post about this question, I've went through question history quite a few times. The resources…
39
votes
5 answers

How to delete (localdb) database if the file is gone

If I run SQL Server Management Studio, and tell it to connect to (localdb)\v11.0, it knows about every database I've ever used, despite the fact that most of the the database files are long gone. If I ask it to delete one of these databases, it…
Bob.at.Indigo.Health
  • 11,023
  • 13
  • 64
  • 111
38
votes
3 answers

Is it normal to use LocalDb in production?

I know that using LocalDb is very good and easy for developement, I wonder if it's good idea to use it in production when I host websites on IIS server? I'm asking because I wonder if it won't have any kind of speed issues in production. This is my…
Stan
  • 25,744
  • 53
  • 164
  • 242
30
votes
1 answer

Purpose of ProjectsV13 LocalDB instance

According to this answer, SQL Server Data Tools uses a private LocalDB instance ProjectsV13, which you're not supposed to use for your own applications. Instead, you should use MSSQLLocalDB or your own private instance. Is this documented anywhere?…
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
29
votes
3 answers

How to change the default connection to a server in Visual studio 2012 SQL Project?

In visual studio 2012 sqlproj, the default connection button always connect to the (localdb)\Projects by default. How do I change that? Every time I need to disconnect and connect again to change the server.
suresh2
  • 1,129
  • 2
  • 15
  • 25
29
votes
2 answers

User Instance of SqlLocalDb

I am getting this Exception When I am trying to access database from C#. My Connection String is Data Source=(localdb)\v11.0;integrated security=true;User Instance = true;AttachDbFileName=C:\Users\UserName\Desktop\DB\TestDB3.mdf Exception is The…
Siddharood
  • 908
  • 1
  • 12
  • 24
27
votes
7 answers

I can't get a Sql Server localdb connection to work on a computer that does not have SqlServer Express installed

I have a C# console application written using Visual Studio 2012. In the application I am using a Sql Server localdb connection to a database to store information. This is working fine on several computers, all of which have Visual Studio…
27
votes
6 answers

How do I change "Database default locations" for LocalDB in SQL Server Management Studio?

Connect to LocalDB in SSMS Open Server Properties -> Database Settings Change Data/Log/Backup locations -> click OK When I click OK I get this error: Found some blogpost and changed this in regedit but it didn't help. Anyone got any other ideas…
PussInBoots
  • 11,028
  • 9
  • 52
  • 84
27
votes
5 answers

Why can't I connect to a SQL Server 2012 LocalDB shared instance?

I'm trying to set up a SQL Server 2012 LocalDB (RTM, x64) shared instance on my Windows 7 x64 machine and I can't seem to connect to the shared instance. I'm using an Administrator command prompt for all of the setup. Here's how I'm creating the…
26
votes
9 answers

How do I copy SQL Server 2012 database to localdb instance?

I'm looking to copy a SQL Server 2012 Standard database to my localdb instance. I've tried the wizard which complains that localdb isn't a SQL Server 2005 or later express instance. I also did a backup/restore but upon the restore in my localdb I…
Corey Blair
  • 469
  • 1
  • 7
  • 13
25
votes
2 answers

How to prevent SQL Server LocalDB auto shutdown?

I'm using SQL Server 2012 Express LocalDB. Instances seem to stop automatically after 10 minutes if there is no activity on them. Is there a clean way to keep an instance running forever?
user1947865
  • 251
  • 1
  • 3
  • 3
24
votes
5 answers

How do I connect to an older sql database using LocalDb in VS 2012?

I am trying to construct a connection string to a 2008 SQL Express database file in VS 2012. I am getting an error dialog: This database file is not compatible with the current instance of SQL Server. To resolve this issue, you must upgrade the…
ATL_DEV
  • 9,256
  • 11
  • 60
  • 102
1
2
3
68 69