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
24
votes
4 answers

Connecting to SQL Server LocalDB using JDBC

Is it possible to connect to a SQL Server LocalDB using JDBC? It appears that (as of Dec 2011) it was not possible. Do you know of a workaround or change in status?
Sri Sankaran
  • 8,120
  • 4
  • 38
  • 47
22
votes
9 answers

How to install LocalDB 2016 along with Visual Studio 2017?

After installing Visual Studio 2017 with the SQL Server Data tools feature checked, I noticed LocalDB was not installed. How can I add SQL Server LocalDB 2016 to my Visual Studio 2017 installation? Did I miss a checkbox when installing VS2017, or is…
Rudey
  • 4,717
  • 4
  • 42
  • 84
22
votes
1 answer

confusion about SQL Server Express and localdb

I need to deploy a WCF service with a database on client machines. I am confused about SQL Server Express. I need to verify all of the following. When attaching database files in the App_Data folder, do I still need to install SQL Server Express…
Costa
  • 3,897
  • 13
  • 48
  • 81
22
votes
4 answers

SQL2012 LocalDB: how to check in c# if it is currently installed?

How to check in c# code if LocalDB currently installed? also, how to check if SQLNCLI11 presents in system?
ZedZip
  • 5,794
  • 15
  • 66
  • 119
21
votes
3 answers

Windows API call "RegGetValueW" returned error code: 0

I am getting Windows API Call Error Code : 0 I have installed SSMS 2018 and was trying to find out if I have any other versions installed. For that I ran sqllocaldb versions in CMD but got the following message: Windows API call "RegGetValueW"…
Ravi
  • 221
  • 3
  • 6
20
votes
1 answer

Unable to connect to localDB in VS2012 – "A network-related or instance-specific error occurred while establishing a connection to SQL Server..."

This is strange as I'm able to connect to localDB through SSMS 2008R2 with the same connection string ("Data Source=(LocalDB)\v11.0;Integrated Security=true") Only C# code is unable to connect, I have tried increasing login time with Connect…
Varun K
  • 3,593
  • 2
  • 25
  • 26
19
votes
1 answer

Create user and assign permission to user in LocalDB in Visual Studio

Can someone please tell me how I can create a user with a password and grant it owner permission to a database that I created in LocalDB in Visual Studio. It creates a user with no login but I need to create one with a password and owner rights to a…
SP1
  • 1,182
  • 3
  • 22
  • 47
19
votes
5 answers

How to deploy ASP.NET MVC 4 application using localDB to local IIS on Windows 7?

When I try to run my ASP.NET MVC 4 application using Local IIS on Windows 7 with Visual Studio 2013. I run into the following error when the application tries to connect to localDB\v11.0 Server Error in '/' Application. A network-related or…
allenylzhou
  • 1,431
  • 4
  • 19
  • 36
18
votes
1 answer

What is the best way to attach existing database to sql localdb?

Context I'm working on a desktop app which must be able to run in case of connection loss with the distant sql server : a SQL Server Express (I know...) 2012. I'm working on Visual Studio Express 2013. So I figured out that my best option is to use…
IronSlug
  • 492
  • 3
  • 15
18
votes
2 answers

How to RESEED LocalDB Table using Entity Framework?

Is There any way to RESEED a LocalDB Table using EF? I'd prefer not to use this SQL Command : DBCC CHECKIDENT('TableName', RESEED, 0) FYI : I'm using EF 6.1. Thanks alot.
Mahdi Rashidi
  • 1,359
  • 3
  • 18
  • 33
17
votes
3 answers

Sql local database cannot be opened

I recently installed VS2015 Update 2 on two different PC, one at home and one at work, with the same installer file. Now if I open a project with Sql LocalDB on my own PC, I obtain this error: The database 'M:\PROJECTS\BLOG\APP_DATA\myBlog.MDF'…
Rotondof
  • 203
  • 1
  • 3
  • 8
16
votes
4 answers

ClickOnce Prerequisites: where is SQL Server Express 2014 LocalDB?

I am creating a clickonce installer for my wpf application from within Visual Studio 2013 Community edition. This application uses a localdb. It works fine on the target machines if I manually install sqlserver express 2014 LocalDB. But I would like…
16
votes
4 answers

IIS connecting to LocalDB

Is there any way so IIS could connect to LocalDB without using the NT SERVICE\NETWORK SERVICE user account. This account has not suitable permissions. I'm looking use some other default account or is there some way that I can use the NETWORK…
Tom Hruby
  • 195
  • 1
  • 1
  • 7
15
votes
2 answers

Using LocalDB with Service Fabric

I have an Actor that upon receiving a request from a WebAPI project, the Actor queries a table using Entity Framework 6. using (var context = new MetadataContext()) { var userStorageAccountId = context.Set() …
shlatchz
  • 1,612
  • 1
  • 18
  • 40
15
votes
5 answers

MSSQLLOCALDB databases aren't listed

I used the ASP.NET 5 Preview Templates in Visual Studio 2015 to create an ASP.NET 5 site. According to the config.json file, there's a database in (localdb)\mssqllocaldb. I want to move that database to my actual SQL Server, but when I connect to…
David
  • 2,782
  • 4
  • 31
  • 47
1 2
3
68 69