Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect to LocalDb

Tags:

ssms

localdb

I installed LocalDb using the SqlLocalDb.msi package and I can connect to it using SSMS using the server name (LocalDb)\v11.0. So far so good. The problem is that when I try to connect to it via a .NET 4.5 application I get the error

The server was not found or was not accessible.

I started with the connection string Data Source=(LocalDb)\v11.0 and then added many things to no avail (integrated security true/sspi, attaching a db, using instances, etc.)

like image 225
Manuel Avatar asked Sep 21 '12 16:09

Manuel


People also ask

How do I find my LocalDB?

To get all existing LocalDB instance names, use: SqlLocalDB.exe i info|i Lists all existing LocalDB instances owned by the current user and all shared LocalDB instances.

How do I connect to SQL Server?

Connect to a SQL Server instanceStart SQL Server Management Studio. The first time you run SSMS, the Connect to Server window opens. If it doesn't open, you can open it manually by selecting Object Explorer > Connect > Database Engine. For Server type, select Database Engine (usually the default option).


2 Answers

I am totally unable to connect to localdb with any tool including MSSMA, sqlcmd, etc. You would think Microsoft would document this, but I find nothing on MSDN. I have v12 and tried (localdb)\v12.0 and that didn't work. Issuing the command sqllocaldb i MSSQLLocalDB shows that the local instance is running, but there is no way to connect to it.

c:\> sqllocaldb i MSSQLLocalDB Name:               MSSQLLocalDB Version:            12.0.2000.8 Shared name: Owner:              CWOLF-PC\cwolf Auto-create:        Yes State:              Running Last start time:    6/12/2014 8:34:11 AM Instance pipe name: np:\\.\pipe\LOCALDB#C86052DD\tsql\query c:\> c:\> sqlcmd -L  Servers:     ;UID:Login ID=?;PWD:Password=?;Trusted_Connection:Use Integrated Security=?; *APP:AppName=?;*WSID:WorkStation ID=?; 

I finally figured it out!! the connect string is (localdb)\MSSQLLocalDB, e.g.:

$ sqlcmd -S \(localdb\)\\MSSQLLocalDB 1> select 'hello!' 2> go  ------ hello!  (1 rows affected)     
like image 95
Chris Wolf Avatar answered Oct 01 '22 17:10

Chris Wolf


Use (localdb)\MSSQLLocalDB. That is the LocalDB instance intended for applications, independent of Visual Studio version.


Disregard my original answer: "With SQL Server 2014 Express LocalDB, use (localdb)\ProjectsV12. This works in both Visual Studio 2013 and SQL Server 2014 Management Studio." While ProjectsV12 will indeed give you a LocalDB instance, it's the wrong one, intended for use by SQL Server Data Tools.

like image 39
Edward Brey Avatar answered Oct 01 '22 17:10

Edward Brey