go-sqlcmd
go-sqlcmd copied to clipboard
Cannot connect to named instance
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?
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.
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
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.