6

I've got a large SQL script (1gb) that I'm trying to run against a (localdb)\v11.0 instance, using SqlCmd in a command line window, but so far no commands I've tried have worked with it at all.

E.g.

sqlcmd.exe -S "(localdb)\v11.0" -Q "select 1"

fails with a generic connection error:

A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections.

However

sqlcmd.exe -S "MY-PC" -Q "select 1"

is fine with the SQL Server instance on my PC.

"Allow Remote Connections" is set to true on the (localdb) instance and the user I'm running the sqlcmd with is the owner of it.

Does Sqlcmd actually work with (localdb) instances? Are there any other obvious things I might be doing wrong?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Ted
  • 2,525
  • 2
  • 37
  • 54
  • 1
    Hi,I have experienced this when using the wrong version of sqlcmd for the Localdb in question...http://stackoverflow.com/questions/10214688/why-cant-i-connect-to-a-sql-server-2012-localdb-shared-instance Is that possible? O –  Jul 07 '15 at 13:16
  • Gah, yes that seems to be it. I navigated through to the latest Sql Server installation "C:\Program Files\Microsoft SQL Server\120\Tools\Binn", but looking more carefully, there's no SqlCmd.exe in there, so it would have defaulted back to the one set in my Env, rather than SQL\110 . When I run sqlcmd from 110\tools\binn it's fine. Many thanks! – Ted Jul 07 '15 at 13:27

2 Answers2

2

I believe this can happen when you use the wrong version of SQLCMD for the LocalDB instance as described in this post...

Why can't I connect to a SQL Server 2012 LocalDB shared instance?

Hth, Ojf

Community
  • 1
  • 1
0

Change your working folder to C:\Program Files\Microsoft SQL Server\110\Tools\Binn

cd "C:\Program Files\Microsoft SQL Server\110\Tools\Binn"

and try again...

sqlcmd.exe -S "MY-PC"

Andy Lai
  • 1,714
  • 1
  • 14
  • 17