sqlcmd client Connection error to sqlserver on windows server

本文最后更新于:2024年8月9日 晚上

Case scenario

I installed SQL Server 2019 on Windows Server 2022, When I successful installed SQL Server, local connection with sql server management studio all good. Well, when I tried to using sqlcmd to connect the SQL Server on another Linux machine.

I encountered an issue like this:

1
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..

Troubleshooting

Check SQL server connection protocol

we know sqlcmd use TCP/IP communicating with the server , so I checked the the server side connection protocol, make sure TCP/IP protocol enabled. Basically, It has been enabled by default. But we still need to make sure it has been enabled.

image-20240409103849823

Check IPAddress and TCP Port 1433

why we check this?

Because on sql server TCP/IP configuration parameter, there is an optional value called Dynamic TCP Port, we have to disable it and set a static IP and port.

Checked TCP 1433, Well, not listening. Further checking, Dynamic TCP Port value set with 0,that means enabled, we had to leave it blank to disable it. At meanwhile, We have to enable the IP just like below:

image-20240409110129790

image-20240409105856847

After Restarting the SQL server, check again:

image-20240409111031743

image-20240409111122648

Add firewall rules for SQL server(optional)

This step is optional, When you still have connection issues you can try this .

image-20240409104338350

image-20240409104412171

image-20240409104446752

image-20240409104507857


sqlcmd client Connection error to sqlserver on windows server
https://git.msft.vip/2024/04/09-sqlcmd-client-Connection-error-to-sqlserver-on-windows-server/
作者
Jas0n0ss
发布于
2024年4月9日
更新于
2024年8月9日
许可协议