go-sqlcmd icon indicating copy to clipboard operation
go-sqlcmd copied to clipboard

LocalDB connections

Open thorstenkampe opened this issue 2 years ago • 11 comments

Will go-sqlcmd support LocalDB connections on Windows? (Basically the equivalent to sqlcmd -S (localdb)\MSSQLLocalDB -E.)

On Windows I get the following error with the latest go-sqlcmd 1.4.0: "no named pipe instance matching 'MSSQLLOCALDB' returned from host '(localdb)'".

thorstenkampe avatar Oct 19 '23 20:10 thorstenkampe

It would be great to fix this. Is it something we need to fix in the underlying go-mssqldb driver?

stuartpa avatar Oct 20 '23 14:10 stuartpa

I don't know if it needs to be in the driver. I think there's some logic needed to calculate the right pipe name to connect to. We'd probably only support automatic instances that are started externally. The documentation shows how you may be able to connect using go-sqlcmd today by doing the pipe name calculation yourself.

eg np:\\.\pipe\LOCALDB#F365A78E\tsql\query

shueybubbles avatar Oct 20 '23 15:10 shueybubbles

C:\Program Files\Microsoft SQL Server\150\Tools\Binn>SqlLocalDB.exe info MSSQLLocalDB
Name:               MSSQLLocalDb
Version:            15.0.4153.1
Shared name:
Owner:              REDMOND\******
Auto-create:        Yes
State:              Running
Last start time:    24/10/2023 06:15:04
Instance pipe name: np:\\.\pipe\LOCALDB#4B62CD62\tsql\query

C:\>sqlcmd -S np:\\.\pipe\LOCALDB#4B62CD62\tsql\query
Access is denied.
Access is denied.

C:\>"C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\SQLCMD.EXE" -S np:\\.\pipe\LOCALDB#4B62CD62\tsql\query
1>

I get "Access Denied" when using the correct np (obtained from SqlLocalDB.exe) with go-sqlcmd. It works fine with the ODBC version.

stuartpa avatar Oct 24 '23 13:10 stuartpa

I had to uninstall the sqlcmd go version and use sqlcmd ODBC version =(

That's the solution (not good) that I found.

willsbctm avatar Dec 20 '23 15:12 willsbctm

I'm having the same issue. When is this being pulled from backlog and fixed?

weberms avatar Jul 28 '24 04:07 weberms

I'm having the same issue. any updates?

iopaul avatar Dec 31 '24 14:12 iopaul

With 1.8.2 I am able to use the pipe name directly.

10:24:23.79 e:\git\go-sqlcmd>sqllocaldb info mssqllocaldb
Name:               MSSQLLocalDB
Version:            15.0.4382.1
Shared name:
Owner:              redacted
Auto-create:        Yes
State:              Running
Last start time:    12/31/2024 10:24:23 AM
Instance pipe name: np:\\.\pipe\LOCALDB#6894F7B1\tsql\query

(built from cmd\modern folder)
10:25:10.12 e:\git\go-sqlcmd\cmd\modern>modern -S np:\\.\pipe\LOCALDB#6894F7B1\tsql\query
1> select @@servername
2> go

--------------------------------------------------------------------------------------------------------------------------------
redacted\LOCALDB#6894F7B1

(1 row affected)
1>

It's a poor substitute but worth a try until we have time to address it.

shueybubbles avatar Dec 31 '24 16:12 shueybubbles