microsoft / go-sqlcmd

The new sqlcmd, CLI for SQL Server and Azure SQL (winget install sqlcmd / sqlcmd create mssql / sqlcmd open ads)
https://learn.microsoft.com/sql/tools/sqlcmd/go-sqlcmd-utility
MIT License
323 stars 56 forks source link

LocalDB connections #470

Open thorstenkampe opened 8 months ago

thorstenkampe commented 8 months ago

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)'".

stuartpa commented 8 months ago

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

shueybubbles commented 8 months ago

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

stuartpa commented 8 months ago
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.

willsbctm commented 6 months ago

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

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