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
0 answers

Connect to SQL 2012 Express database on local machine via JDBc

I'm trying to connect to my local MSSQL Express database but nothing seems to work. I tried all these variations, but can't get it to work:
Adam
  • 6,041
  • 36
  • 120
  • 208
0
votes
1 answer

Why can't you use LocalDb in a Windows Azure Website

Regardless of whether it is a good idea or not, why is LocalDb not supported in Windows Azure Websites? I'd like to understand the technical reasons.
Matt Whetton
  • 6,616
  • 5
  • 36
  • 57
0
votes
1 answer

When deploying localdb/v11.0 no longer works

I am attempting to deploy an asp.net application to a Windows Server 2012 server and have come across an issue where the application will no longer connect to a localdb server on SQL Server 2012. I am able to access the localdb database in…
Steven Law
  • 31
  • 1
  • 7
0
votes
0 answers

LocalDB vs SQL Server in Visual Studio 2012

If I install SQL Server, does it overwrite the localDB? Is my database using the localDB still usable? I'm using Visual Studio 2012.. My projects from the previous version.. VB.NET 2005 when I open it in VB.NET 2012 there are lots of errors now..…
user3211476
  • 37
  • 1
  • 12
0
votes
0 answers

cte doesn't show parentid correctly

db: menuid Name Url Parentid Value 1 Products node NULL 0 2 Windows node …
0
votes
1 answer

SQL Server 2012 Express / VB.NET Database Application Issue

Please forgive me if I am overlooking something really obvious here, as I am totally new to programming. I have spent the last couple of days trying to troubleshoot an issue I have been having. Long story short, I have a CRM app that I am building…
ocsean
  • 35
  • 7
0
votes
1 answer

SQLCLR Trigger/Procedure in LocalDB?

I'm trying to get SQL CLR procedures working with LocalDB (2012). My trigger and procedure (below) are never called. I'm creating the LocalDB with Entity Framework 6. Is the trigger supposed to work in this scenario? using System; using…
Brannon
  • 5,324
  • 4
  • 35
  • 83
0
votes
1 answer

LocalDB operations within impersonation context

Using the following method I impersonate as local administrator user (with elevated privileges) and pass the function that has to be executed within the impersonation context. /// /// Attemps to impersonate a given windows user and…
Swissy
  • 11
  • 3
0
votes
1 answer

Asp.Net MVC development with Visual Studio LocalDB

I am currently studying software development and for a project I will be developing a database driven application in Asp.Net MVC. I am completely new to MVC but have experience in Asp.Net Web Forms. I have done a small app using the Entity…
user2437588
0
votes
0 answers

Copy data from production database back to SqlLocalDb

I've had to reinstall my OS so have lost the development Sql LocalDb instance of my website's database. However, I do have the live database on my production server. I want to recreate my LocalDb from the live database. How do I do this? I used to…
FloatLeft
  • 1,317
  • 3
  • 23
  • 40
0
votes
1 answer

Add a video to a data table in visual studio

Am I able to add a video to a data table in my local db. And if so what would be the data type. I am using a file upload controller to upload the videos and I have 3 fields the title, category & description. Is that the best practice or is there…
Ozzy Sh
  • 19
  • 6
0
votes
3 answers

Entity Framework (Code First) and WPF

Originally, I was following along in this ASP.NET MVC4 tutorial on using EF: http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/creating-an-entity-framework-data-model-for-an-asp-net-mvc-application Everything worked fine there, so I…
Pretzel
  • 8,141
  • 16
  • 59
  • 84
0
votes
1 answer

Can't restore database with LocalDB

I have been using this code for about 2 years to restore 2008 r2 backup to 2008 r2 and it works every time. I am now trying to use the same code to restore from 2008 r2 backup to 2012 localdb and it fails every time. The error message is below. Not…
P a u l
  • 7,805
  • 15
  • 59
  • 92
0
votes
0 answers

LocalDB doesn't work correctly

when I don't see my databases in LocalDB, Is there any service to Start? I am using SQL Management Studio 2008 and my local instance works correctly but I don't know what's happening to LocalDB. status both of them in Object Explorer
Sirwan Afifi
  • 10,654
  • 14
  • 63
  • 110
0
votes
2 answers

How to simulate a data exception with localdb

I'm using a LocalDB database with EntityFramework on an ASP.NET MVC project. How can I simulate a connection failure to test the following try...catch block? try { if (ModelState.IsValid) { db.Entry(course).State = EntityState.Modified; …
Evonet
  • 3,600
  • 4
  • 37
  • 83