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

db.mdf is being used by another process

Right now by code looks like the following: private void DatabaseIntegrityCheck() { try { string m_checksum; using (FileStream stream = File.OpenRead(@"C:\~\db.mdf")) { SHA256Managed sha = new…
Kala J
  • 2,040
  • 4
  • 45
  • 85
0
votes
1 answer

Incorrect Decimal precision and scale when creating database with Code First in Entity Framework 6.1

I have a model that inherits from IdentityDbContext in my project, created from the project template of ASP.NET MVC created with Visual Studio 2013 Update 2. public partial class MyModel : IdentityDbContext { public…
yosbel
  • 1,711
  • 4
  • 20
  • 32
0
votes
1 answer

Find database in SQL Server Object Explorer

I am using VS2013 Express Web Edition and I have coded a C# MVC 5 Internet application, and wish to delete the database from the SQL Server Object Explorer. Here is my connection string: "Data…
Simon
  • 7,991
  • 21
  • 83
  • 163
0
votes
2 answers

Developing SQL Server DB in LocalDB with Advanced (Full Server) - Features

We're developing our database with SSDT in Visual Studio 2013. We want to build TVFs with full text search features. Visual Studio installs a LocalDB Server so we don't need to install any other stuff on the developer machines to get the application…
0
votes
2 answers

SQL Server LocalDB to SQL Server 2008 R2

I developed a C# winforms project with SQL Server database. My boss told me that target machines had Win 7 and Win 8. So I wasn't worried with system requirements so I used LocalDB with .Net Framework 4.5.1. Now my boss changed his mind and the…
hi itsme
  • 431
  • 1
  • 9
  • 23
0
votes
1 answer

Enumlike object's(Person) status field class in ASP .NET MVC

I would like to create class Person which will have int Id; string Name etc. but there is one thing I don't know how to solve. I'll be calling every person and after the call I would like to set status for the result of call and I want only those:…
Yoda
  • 17,363
  • 67
  • 204
  • 344
0
votes
1 answer

Localdb connection from c# .net 3.5

We created a windows application in .net 3.5. When i run it on my development machine (installed application, not from VS) i can connect to a local db database server using the servername: (localdb)\v11.0. When starting on the client's computer i…
P. Zantinge
  • 185
  • 1
  • 15
0
votes
1 answer

restore sql localdb with vb.net

I am trying to retrieve a backup copy of the sql localdb through the environment of .net , but I get error . the error : RESTORE cannot process database 'C:\Users\Emad-VB\Desktop\KizeN\KizeN\bin\Debug\Data\Data\DataStore.mdf' because it is in use by…
0
votes
1 answer

Using localdb with for WF4.5 persistence fails

I am trying to create unit tests for a Workflow that uses SqlWorkflowInstanceStore for it's persistent store. When I try to create and instance I get the following error: The execution of the InstancePersistenceCommand named…
0
votes
1 answer

Does having a Microsoft SQL Server 'LocalDB' on your computer use up CPU resources?

I've just installed VS2013 Premium on my Win8.1 and noticed this in my Sql Server Object Explorer .. Does this mean that I have Sql Server running as a service and therefore consuming CPU, etc? How can I confirm this please? UPDATE: here's a…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
0
votes
1 answer

Why is my web.api project still looking for an .mdf file?

I have a code first web.api project that was working fine with the automatically created .mdf in the App_Data folder. I decided to move my app to IIS and modify the app pool config to load the user profile, again, no problem. Then I loaded the…
sonicblis
  • 2,926
  • 7
  • 30
  • 48
0
votes
0 answers

c# localdb v11 not saving to file

I want to create a program for my school, handling marks and certificates. To save the data I have to use a "local" network shared database-file, because we are using Citrix and there is no possibility to setup an seperate SQL-Server. I tried it…
gu471
  • 173
  • 12
0
votes
1 answer

LocalDb Unspecified Initial Catalog?

I've recently been placed on a project using EF 6.0 and Code First principles. The ApplicationDbContext is loaded from this connection string: name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Integrated Security=True"…
0
votes
1 answer

Wix: Determine if SqlLocalDB is installed

I'm trying to determine is it LocalDb installed and i tried to go the way from this link Determine if SqlLocalDB is installed But i've got an error on my log file that: Registry key not found. Key = 'SOFTWARE\Microsoft\Microsoft SQL…
0
votes
1 answer

Import schemas / procedures from SQL Server 2012 database into LocalDB for unit-testing

I'm pretty new to unit-testing. I hope I can get some ideas from you guys how I can solve my "problems". Here is what I want to do: We have some SQL Server 2012 databases. For unit-testing in Visual Studio 2012, I want to programmatically create a…
WhoisIt
  • 123
  • 2
  • 10