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

Cannot connect to named instance

Open SSchwaiger opened this issue 1 year ago • 3 comments

I'm running sqlcmd with an inline PowerShell task in a Azure DevOps pipeline.

The system diagnostic says: ##[debug]sqlcmd -S 'm-sql2022\UTF8,1433' -U 'abc' -P '***' -C -Q "CREATE DATABASE [LogDb]" -m -1

When the script is executed, the following error appears:

parse "sqlserver://abc:***@m-sql2022%5CUTF8:1433?app+name=sqlcmd&trustservercertificate=true": invalid URL escape "%5C"

Is this a bug or do I need to encode named instance addresses differently?

SSchwaiger avatar Oct 05 '24 19:10 SSchwaiger

The problem appears to be your connection string here. You specify both port and instance name (it should be one or the other). I would suggest trying:

sqlcmd -S 'm-sql2022\UTF8' -U ...

or

sqlcmd -S 'm-sql2022,1433' -U ...

Considering, however, your named instance is running on the default port (a very odd choice for a named instance), you could just completely omit the name/port too, as port 1433 would be used by default.

LarnuUK avatar Oct 28 '24 16:10 LarnuUK

Hi I have the same issue and it not using default port because I am connecting to failover group and the DBA decided to give a non standard port. I also have an instance name too that is not default. Anyway to specify port and instance

DHCodi avatar Nov 05 '24 07:11 DHCodi

If you know the port number, just use it, no need for the instance name. If you don't know the port number, the browser service has to be running on the server so you can use the instance name.

shueybubbles avatar Nov 05 '24 16:11 shueybubbles