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

Invalid object name LocalDb Table

I'm trying to run a simple SQL query on a LocalDb database in Visual Studio 2013. Here's the query in a file GrabWords.sql: SELECT * FROM Words where Words is a table in the NextGen.mdf database. When I run this, I get the error: Invalid…
hubatish
  • 5,070
  • 6
  • 35
  • 47
0
votes
1 answer

LocalDB- master database , backup/restore feature

I have a C#,.net application which connects to a SQLexpress database. I am changing the database to localDB.Now there are couple features like Database restore/backup - i have a common stored procedure in master and i call that for the same. get…
user1687824
  • 807
  • 2
  • 10
  • 24
0
votes
1 answer

Install SQL Server 2014 LocalDb for Azure testing?

I have a web site running in an Azure Cloud Services Web Role, which uses an Azure SQL Database. For development, I use SQL Server LocalDb, which was installed with Visual Studio 2013. Now that SQL Server 2014 is released, should I switch to its…
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
0
votes
1 answer

Windows Phone 8 localdb thread safety

I have a WP8 app that has multiple (at times, up to 40) threads that have to get the data from a webservice and then commit to a localdb. I have implemented an AutoResetEvent-based pattern where each Repository method looks somewhat like this: …
zaitsman
  • 8,984
  • 6
  • 47
  • 79
0
votes
1 answer

SQL Server Database Project / Cannot execute view in visual studio 2013

I am creating a new sql server database project in visual studio 2013. I try to create a new view as follows CREATE VIEW [dbo].[View1] AS SELECT * FROM Company When I try to execute in visual studio, it return something like this. Msg 208, Level…
0
votes
1 answer

Why does not SqlConnectionFactory work with LocalDb?

I know about LocalDbConnectionFactory but I'm interested why using SqlConnectionFactory with the string "Data Source=(localdb)\v11.0;Integrated Security=True; MultipleActiveResultSets=True" causes…
0
votes
0 answers

Encrypted database for offline application?

We currently facing the problem to provide an offline version of a Server-Client-App (WCF/Silverlight). On our server we currently working with a heavy weight MSSQL Server, storing global and user data. Now, to provide an offline version, we have…
germanSharper
  • 911
  • 9
  • 13
0
votes
2 answers

how to delete localDB databases in SSMS in one shot

This is related to a previous question How to delete (localdb) database if the file is gone. I use SQL Server Management Studio 2012 to edit local databases created within Visual Studio by connecting to (LocalDB)\v11.0 as server. After a while, I…
0
votes
1 answer

I have problems when try to save records to the LocalDB

I use VS 2012 and LocalDB for storing data. This is my Solution Explorer: I have one simple table in TestDb. Here is structure of that table: I run the program and add some records to the table. And I use BindingNavigator and DataGridView for…
namco
  • 6,208
  • 20
  • 59
  • 83
0
votes
2 answers

Accessing a LocalDB within an ASP.NET website from another project in solution

I have an asp.net mvc 5 website using EF, LocalDB and Code First Migrations. Requirements have now dictated that I need a need to add a console application into the mix to do some scheduled work. However this console app must call into the database…
Sergio
  • 9,761
  • 16
  • 60
  • 88
0
votes
0 answers

Use VS2013 to browse localdb

I am trying to follow along with this article (EF Code First) and whilst the code runs and the output is what I expect, I can't browse to my LocalDb from within VS2013. I see my SQL Server 2012 developer instance but not my LocalDb. I can't find my…
Jason James
  • 1,082
  • 1
  • 14
  • 27
0
votes
1 answer

Can I use a .sqlproj file in my .vbproj environment?

I just got VS2013 because I had to do a system restore... unfortunately during the system restore my project's DB files didn't make it over. So, rather than build a LocalDB from my .vbproj environment I decided to manage it in a separate SQL…
turbonate
  • 159
  • 2
  • 13
0
votes
1 answer

Sharing source for an ASP.NET MVC project that has a database

I have a very simple database (just 3 tables and a dozen rows or so each) that is designed for use with an ASP.NET MVC 5 project. I am using Visual Studio 2013 Ultimate. I want to be able to post my Visual Studio solution for others to download and…
Jazimov
  • 12,626
  • 9
  • 52
  • 59
0
votes
1 answer

SqlServer LocalDB deployed on IIS gives error Invalid object name for Database

I have a MVC 4 application using Sql Server 2012 localDB. Inside the application I am using EntityFramework to access data. I have one raw sql command executing as 'select something from [databasename].[dbo].[something]'. This query works absolutely…
Nik
  • 91
  • 1
  • 1
  • 5
0
votes
2 answers

How can I connect to local SQL Server if MSSQLSERVER service is missing?

I am trying to do some local development on various toy projects for learning purposes. I have Microsoft SQL Server Management Studio 2008 R2 (10.50.1617.0) and Visual Studio Express 2013 for Web installed on my machine. Projects using things such…
bubbleking
  • 3,329
  • 3
  • 29
  • 49