Connect to localdb with sql-cli

2.9k views Asked by At

There is the sql-cli utlity (installed with npm) which I am using to connect to various SQL Server machines. It works perfectly, however when connecting to localdb it responds with an error. So the next command line works:

mssql -s SomeServerAddress

But this one doesnt work:

mssql -s (localdb)\v11.0

And it responds with

\v11.0 was unexpected at this time.

Is there any special formatting for the server name to work?

Thanks.

3

There are 3 answers

7
Andrew 'go-sql' Fenna On BEST ANSWER

its because (localdb)\v11.0 is not an actual instance as it can only be used inside visual studio.

"The localdb is at the heart of SSDT; it’s similar to SQL Server Express under the hood and runs a full version of sqlserver.exe. However this is throttled by the numbers of CPUs and limits on resources. There are quite a lot of limitations; you cannot upgrade the instance and there is no management and the sqlserver.exe does not run as a service. It is not similar to SQL Server Compact as this is feature-less (no stored procedures or functions) it is actually a DLL file that runs in a process from within Visual Studio, but is not available to task manager or windows. It is awakened when the SQL Server Native Client requests a connection from within Visual Studio. It doesn't stay online forever, it shuts down after time. You can configure where it creates the SQL files required to run. The localdb does not support table partitioning or data compression at the moment. However there are not many features that it does not support. You can however configure SSDT to use a full version of SQL Server i.e. the Developer edition, if your project requires unsupported features; by changing the Debug Connections tring in the projects properies." - Andrew J Fenna

0
Francis Omoruto On

You may alreaady have gone on to bigger and better things, but

mssql -s "(localdb)\MSSQLLocalDB"

has worked for me.

Regards

0
Giovanni Bassi On

This works:

 mssql-cli -E -S (localdb)\mssqllocaldb

The -E is for integrated auth, the -S is the server.

If it does not connect, try to start localdb:

sqllocaldb start mssqllocaldb

This is all that is needed. No need to start Visual Studio or any other tool.