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
267
votes
14 answers

How to connect to LocalDB in Visual Studio Server Explorer?

I can't believe I couldn't find a working solution to this after an hour of searching. I'm following this article on Entity Framework 6.0 which gives a simple walk-through on Code First. I created the project and installed the latest EF Nuget…
182
votes
19 answers

ASP.NET 4.5 has not been registered on the Web server

In my Win 7 development machine, and in order to use SQL Express instance instead of the localDB installed by default. I unchecked "Use IIS Express" in my MVC 4 project properties page (Web tab), then I got the following error: ASP.NET 4.5 has not…
Sami-L
  • 5,553
  • 18
  • 59
  • 87
150
votes
4 answers

"Server" vs "Data Source" in connection string

I'm new to SqlServer, right now I have SqlLocalDb installed to work locally. Good, but I can see two connection strings typically and both works: Data Source=(localdb)\v11.0;Integrated Security=true; and Server=(localdb)\v11.0;Integrated…
nawfal
  • 70,104
  • 56
  • 326
  • 368
142
votes
12 answers

EF5: Cannot attach the file ‘{0}' as database '{1}'

I'm encountering the exact issue as described here (read section "Cannot Attach to Deleted MDF File"), but the solution to the problem is not told there... In short the issue is that after deleting the .mdf file, the following exception is thrown…
115
votes
13 answers

How to connect to LocalDb

I installed LocalDb using the SqlLocalDb.msi package and I can connect to it using SSMS using the server name (LocalDb)\v11.0. So far so good. The problem is that when I try to connect to it via a .NET 4.5 application I get the error The server…
Manuel
  • 10,869
  • 14
  • 55
  • 86
73
votes
1 answer

SQL Server (localdb)\v11.0 explained

I'm following Code First to an Existing Database tutorial and noticed that it suggested to connect to (localdb)\v11.0 in learning purposes. I've tried to connect to it using my SQL Management Studio and it worked. But when I've restored a DB backup…
Pavel K
  • 3,541
  • 2
  • 29
  • 44
69
votes
8 answers

What is the connection string for localdb for version 11

I'm trying to do the Code First Walkthrough of the entity framework ( http://blogs.msdn.com/b/adonet/archive/2011/09/28/ef-4-2-code-first-walkthrough.aspx ). I have the latest SQL Server Express and when I check my versions available via command…
Bill Nielsen
  • 866
  • 2
  • 7
  • 18
67
votes
1 answer

LocalDB SQL Server 2014 Express creates 2 instances (localdb)\ProjectsV12 & (localdb)\MSSQLLocalDB?

I'm using SQL Server 2014 Express and the LocalDB option, and I have the following in my SQL Server object explorer pane in Visual Studio 2013... So what is the difference between (localdb)\ProjectsV12 & (localdb)\MSSQLLocalDB?
Ramy Yousef
  • 2,982
  • 2
  • 25
  • 24
62
votes
5 answers

How to set up LocalDb for unit tests in Visual Studio 2012 and Entity Framework 5

We have a Visual Studio 2012 ASP.NET MVC project using Entity Framework 5. There are some unit tests that depend on a database. Setting up the app.config file in the test project to use a central SQL Server database works fine. However, it would be…
60
votes
3 answers

Is there a difference between SQL Server Express (2012) and LocalDB?

In his excellent and popular comparision chart, ErikEJ draws a distinction between SQL Server Express 2012, and SQL Server 2012 LocalDB. However, I can't find such a distinction anywhere else in the MSDN documentation ("LocalDB" isn't even mentioned…
kmote
  • 16,095
  • 11
  • 68
  • 91
56
votes
2 answers

Cannot connect to (LocalDB)\MSSQLLocalDB -> Login failed for user 'User-PC\User'

I am getting an error, While I am trying to connect (LocalDB)\MSSQLLocalDB through SQL Server management studio. I also tried to login with default database as master the error is same. Here is the Server details.
Musakkhir Sayyed
  • 7,012
  • 13
  • 42
  • 65
54
votes
8 answers

How to add LocalDB to Visual Studio 2015 Community's SQL Server Object Explorer?

Problem I don't understand how to make LocalDB show up in the SQL Server Object Explorer. On some VMs, it shows up automatically, on some other VMs, it doesn't. Still, after googling for hours, I don't get it. Current situation I have a clean VM I…
Lernkurve
  • 20,203
  • 28
  • 86
  • 118
54
votes
4 answers

How to install localdb separately?

If I have to work with localdb, do we need to install it separately? I have SQL Server 2008 R2 Management Studio installed, SQL Server 2012 installed, .net 4.0.2 update installed. But I don't see localdb in the PC yet.
user1687824
  • 807
  • 2
  • 10
  • 24
53
votes
6 answers

How do I upgrade SQL Server localDB to a newer version?

Is it possible to upgrade SqlServer localDB from 2012 to 2014? We currently use version 11 from SQL Server 2012. I need to upgrade to version 12 from SQL Server 2014. I would like to be able to do it without losing my tables and data. I installed…
Don Chambers
  • 3,798
  • 9
  • 33
  • 74
52
votes
2 answers

LocalDB deployment on client PC

I am very intrigued by this new version of SQL Server Express. It's not clear (to me) what a setup program should do to deploy an application that use a LocalDB. Is it required to install SQL Server Express on the client PC and then attach the…
Steve
  • 213,761
  • 22
  • 232
  • 286
1
2 3
68 69