1

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.

csg
  • 2,047
  • 2
  • 22
  • 35

3 Answers3

2

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

  • Thanks for response. However why is it possible to connect to localdb from SQL Management Studio? – csg Dec 18 '14 at 14:20
  • 1
    Its because it runs inside the devenv process and can only be used inside visual studio connecting with the SQL Server Native Client. What exactly are you trying to do with connecting the localdb outside of visual studio? – Andrew 'go-sql' Fenna Dec 18 '14 at 14:23
  • For the sake of simplicity, I just want to run sql queries from command line (and making use of its history). – csg Dec 18 '14 at 14:47
  • You cannot do this with the localdb, you can only query the localdb from within visual studio, why don't you connect visual studio to sql server express and query that outside of the IDE? – Andrew 'go-sql' Fenna Dec 18 '14 at 14:51
  • Hey, I am just searching a way to use the command line, not an alternative to it. – csg Dec 18 '14 at 14:59
  • how about using sqlcmd? – Andrew 'go-sql' Fenna Dec 19 '14 at 09:34
  • Yes, it would be an idea. Although I was used with sql-cli (from using remote servers..). Thanks for the response. – csg Dec 19 '14 at 15:04
2

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.

Giovanni Bassi
  • 739
  • 6
  • 18
0

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

mssql -s "(localdb)\MSSQLLocalDB"

has worked for me.

Regards