What Is the Connection String for Localdb for Version 11

Difference between (localdb)\v11.0 and .\sqlexpress in connection string

SQL Server Express is a service-based version of SQL Server i.e. it runs as a service all the time, independently of other applications. When you say .\SQLEXPRESS you are looking for a named instance of SQL Server called SQLEXPRESS that is on your local machine and connected to via a shared memory interface (that's what the dot is).

Local DB is a deployment option for SQL Server Express that runs as an attached process to another application, instead of as a service. It can also be started and stopped by the local db utility. Mostly it's used attached to applications like Visual Studio that just need to use a SQL Server for a while during development, but don't need it running all the time. When you connect to (localdb)\v11.0 you are connecting to one of these attached instances, and in this case using version 11 (you can have multiple versions of localdb on the same machine).

How to connect to LocalDb

I think you hit the same issue as discussed in this post. You forgot to escape your \ character.

How to connect to LocalDB in Visual Studio Server Explorer?

OK, answering to my own question.

Steps to connect LocalDB to Visual Studio Server Explorer

  1. Open command prompt
  2. Run SqlLocalDB.exe start v11.0
  3. Run SqlLocalDB.exe info v11.0
  4. Copy the Instance pipe name that starts with np:\...
  5. In Visual Studio select TOOLS > Connect to Database...
  6. For Server Name enter (localdb)\v11.0. If it didn't work, use the Instance pipe name that you copied earlier. You can also use this to connect with SQL Management Studio.
  7. Select the database on next dropdown list
  8. Click OK

Sample Image

SQL Server (localdb)\v11.0 explained

  1. LocalDB was introduced in SQL Server 2012 CTP3. It’s basically a new version of SQL Express, with same functionality, dedicated to developers. So you don’t need to install any SQL server. If you have installed SQL 2012 or Visual Studio 11 then you already have it, and it runs over .Net 4 or higher. If you are using Visual Studio 11 and have been playing with the new EntityFramework and MVC, you can see it on the default connection string.

  2. MDF is the default extension for SQL Server database files. (Log files are LDF) Also see this question.

  3. You can restore to a specific folder by using RESTORE DATABASE WITH MOVE as documented on MSDN here.

  4. LocalDB is intended for developers, see point 1.

  5. The SQL Server Express blog has an informative post about LocalDB here.

Creating a Connection String and Working with SQL Server LocalDB

The initial Catalog is missing in MovieDBContext connection string.
It needs to be as follows:

 <add name="MovieDBContext"   connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\Movies.mdf;Initial Catalog=Movies;Integrated Security=True" providerName="System.Data.SqlClient"/> 


Related Topics



Leave a reply



Submit