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
0
votes
1 answer

LocalDb - starting a shared instance as other user

I am using a SQL Server 2012 LocalDB instance that is shared for all users. I have also created a SQL Server login which can be used for all users. This are the commands I am using (executing as 'Administrator'): SqlLocalDb.exe create…
ollifant
  • 8,576
  • 10
  • 35
  • 45
0
votes
0 answers

Poor MSBuild performance when deploying SSDT DB project programmatically

I have an SSDT database project. I've set up a publish profile that publishes it to an SQL Server 2012 localdb instance. I have found some code that can be used to publish the database programmatically: First import these: using…
Sam
  • 40,644
  • 36
  • 176
  • 219
0
votes
0 answers

MVC4 EF Database Creation and Seeding Issue

I getting an update error when trying to seed my database. Not sure if my structure is correctly setup but essentially you create a casefile which contains very basic information, then you create a more complex file by creating a ot or pt casefile…
jbolt
  • 688
  • 3
  • 16
  • 37
0
votes
1 answer

Cannot log in to LocalDB

I accidentally deleted my domain logon from SQL Server LocalDB. It was the only logon on the server. How can I get access back to my instance? Every time I try connecting I get the message Logon failed for domain\user. I tried reinstalling and…
Sam
  • 4,219
  • 7
  • 52
  • 80
0
votes
1 answer

Which connection string WSAT uses

I create a new ASP.NET MVC project with internet template. I build the solution. I open ASP.NET Web Site Administration Tool (WSAT). I click the security tab I get this error: "Unable to connect to SQL Server database." I am using Visual…
kroiz
  • 1,722
  • 1
  • 27
  • 43
0
votes
1 answer

How to deploy image files along with Windows Forms through ClickOnce in C#?

I have a winform Windows Forms application in .NET 4.5 and C# (Visual Studio 2012). It uses localDb to set a database in each user's machine through ClickOnce. I have more than 100,000 images which are not stored in the database, and I want to…
peyman
  • 490
  • 7
  • 10
0
votes
1 answer

Deploy LocalDB project to SQL Server 2012 Host

I am trying to deploy my Visual Studio 2012 express LocalDB project to a remote host (another server in the sandbox) which is runnning SQL SERVER 2012 express. I changed the connection string in the web.config to match the instance name but it still…
0
votes
1 answer

LocalDB Not Working

I just installed VS 2012 Express on a fresh Windows image and plan to use the built in localdb functionality to handle SQL databases without installing SQL Server Express. I can the instance name set to (localdb)\v11.0. When I attempt to add an SQL…
Scott
  • 93
  • 2
  • 11
0
votes
2 answers

Connectionstring to mdf file

I've created this MVC4 web application and went with a local MDF (localdb?). It's located in the \App_Data folder of my project. It's name is SiteDatabase.mdf. But right now im struggling with the connection string, how can I "link" it up? I got…
Jason94
  • 13,320
  • 37
  • 106
  • 184
0
votes
1 answer

IF response unexpected result in stored procedure, unique key violation

I might have looked on this too long, so i hope someone can help me out here. i'm playing around with comparing files metadata to identify unique data chunks, and thereby detect deduplication potential... here goes. drop proc insertFile go create…
Christopher Bonitz
  • 828
  • 1
  • 10
  • 22
0
votes
3 answers

localdb readonly database problems

enviroment visualStudio 2012 localdb v11 a solution with 3 projects on it: 1st class library with an ORM database model, and a local db Localdb.mdf inside App_Data directory. 2nd is a web project that uses this database model. and 3rd a c# console…
jlsfernandez
  • 160
  • 3
  • 16
0
votes
1 answer

Unified connection string for MS SQL Express and SQL LocalDb?

I need to support SQL Express and LocalDb in my ASP.NET application. This is a sample app for demo purposes and not a real website. Currently the app is shipped with LocalDb connection string:
IT Hit WebDAV
  • 5,652
  • 12
  • 61
  • 98
0
votes
0 answers

Can't connect to local SQL Server DB when I have no internet connection

If I have an internet connection my local website connects to my local database just fine. I am wanting to work remotely without internet connection... How can I set things up so that I can connect?
Ben Call
  • 976
  • 1
  • 10
  • 16
0
votes
1 answer

Get filepath to LocalDB file from connection string in .NET

How to get the filepath to the .mdf file of a LocalDB database from its connection string in .NET? Example string: Data Source=(LocalDb)\v11.0;Initial Catalog=MyDb;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\MyDb.mdf
angularsen
  • 8,160
  • 1
  • 69
  • 83
0
votes
3 answers

failure deploying LocalDB app to Arvixe

I'm trying to deploy a WCF Data Service to Arvixe. The data service is built on Entity Framework 5 and Data Services 5.4. It creates a fair number of LocalDB databases (named according to runtime input) and runs fine locally. There is no connection…
Brannon
  • 5,324
  • 4
  • 35
  • 83