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
342 stars 60 forks source link

sqlcmd -L command return strange strings #474

Closed AnyiYang closed 10 months ago

AnyiYang commented 11 months ago

My customer runs sqlcmd -L and it returns strange string like following:

Servers: ;UID:Login ID=?;PWD:Password=?;Trusted_Connection:Use Integrated Security=?;APP:AppName=?;WSID:WorkStation ID=?;

The issue can be reproduced in my server with sqlcmd shipped with SQL 2019, SQL 2022. The issue also exists when I use go-sqlcmd:

C:\Windows\System32>sqlcmd -?

Version v1.4.0

C:\Windows\System32>sqlcmd -L

Servers: ;UID:Login ID=?;PWD:Password=?;Trusted_Connection:Use Integrated Security=?;APP:AppName=?;WSID:WorkStation ID=?;

I debuged the sqlcmd shipped with SQL 2022. The issue is that when sqlcmd tries to fetch server list from return result of SQLBrowseConnectW of driver (this is msodbcsql), it could not handling well when there is no server name between { and } in the result. But I think go-sqlcmd might not use msodbcsql. Not sure if it also hit the same string handling problem. Please help to have a check on the issue.

shueybubbles commented 11 months ago

go-sqlcmd doesn't implement a real browse, it always returns the same string that ODBC sqlcmd prints when the list is empty. See https://github.com/microsoft/go-sqlcmd/blob/7002492d79c93015a7c28988e4284c62205e5da0/cmd/sqlcmd/sqlcmd.go#L219

I just assumed whatever ODBC sqlcmd printed was correct.

shueybubbles commented 10 months ago

i can fix sqlcmd to use the browser service locally, at least. But I would keep backward compatibility for the empty case.

stuartpa commented 10 months ago

@AnyiYang -> can you provide some details on what your customers is using -L for. Is it just to enumerate the local instances on the machine, or something else?