我的计算机上有3个Sql server实例,但我不记得每个端口都在运行。我可以运行配置管理器来查找它,但有没有更简单的方法从SQLCMD执行此操作?
答案 0 :(得分:3)
此查询将返回使用的TCP端口。
SELECT
e.name as ProtocolName
,ec.local_tcp_port as Port
,ec.local_net_address as IP
FROM
sys.endpoints e
LEFT JOIN
sys.dm_exec_connections ec
ON
ec.endpoint_id = e.endpoint_id
where
e.name = 'TSQL Default TCP'
GROUP BY
e.name
,ec.local_tcp_port
,ec.local_net_address