我已经尝试了所有能找到的方法来让我的 SQL Server 默认实例监听端口 1433,但似乎没有任何效果。
这是我所做的一切:
SQL Server 配置管理器,位于 MSSQLSERVER 协议中
- 已启用TCP/IP
- 将“全部监听”设置为“否”
- 在“IP 地址”选项卡中,将“IPALL”下的“TCP 动态端口”字段设置为空白
- 在IP 地址选项卡中,将IPALL下的TCP 端口设置为 1433
- 重启服务
然后我使用以下命令检查了它正在监听的端口:
netstat -ano | findstr <sqlservr.exe PID>
我得到的结果是:
TCP 0.0.0.0:9822 0.0.0.0:0 LISTENING 11608
TCP [::]:9822 [::]:0 LISTENING 11608
我多次卸载并重新安装了 SQL Server(开发版),每次我都会得到不同的端口,但从来都不是 1433,而且每次无论我做什么,我都无法让它监听 1433。
查询结果:
EXEC xp_readerrorlog 0, 1, N'listening on';
如下:
LogDate ProcessInfo Text
----------------------- ------------ -------------------------------------------------------------
2025-02-22 15:40:56.670 Server Server is listening on [ 'any' <ipv6> 9822] accept sockets 1.
2025-02-22 15:40:56.670 Server Server is listening on [ 'any' <ipv4> 9822] accept sockets 1.
我还尝试将“全部监听”设置为“是”,但无法启动 SQL Server 服务。我在事件查看器中发现以下错误(每行来自单独的条目,按时间倒序排列)
Server TCP provider failed to listen on [ 'any' <ipv6> 1433]. Tcp port is already in use.
TDSSNIClient initialization failed with error 0x271d, status code 0xa. Reason: Unable to initialize the TCP/IP listener. An attempt was made to access a socket in a way forbidden by its access permissions.
TDSSNIClient initialization failed with error 0x271d, status code 0x1. Reason: Initialization failed with an infrastructure error. Check for previous errors. An attempt was made to access a socket in a way forbidden by its access permissions.
Could not start the network library because of an internal error in the network library. To determine the cause, review the errors immediately preceding this one in the error log.
SQL Server could not spawn FRunCommunicationsManager thread. Check the SQL Server error log and the operating system error log for information about possible related problems.
更多信息:
在 SSMS -> 数据库服务器属性对话框 -> 连接选项卡中选中允许远程连接到此服务器
防火墙中已打开端口 1433,具体如下所述
New-NetFirewallRule -DisplayName "SQLServer default instance" -Direction Inbound -LocalPort 1433 -Protocol TCP -Action Allow New-NetFirewallRule -DisplayName "SQLServer Browser service" -Direction Inbound -LocalPort 1434 -Protocol UDP -Action Allow
命令结果
netsh int ipv6 show excludedportrange protocol=tcp
> netsh int ipv6 show excludedportrange protocol=tcp Protocol tcp Port Exclusion Ranges Start Port End Port ---------- -------- 80 80 443 443 1025 1124 1225 1324 1325 1424 1425 1524 1526 1625 1640 1739 1834 1933 12428 12527 50000 50059 * * - Administered port exclusions.