How to find SQL Server running port?

2020-01-25 13:06发布

Yes I read this How to find the port for MS SQL Server 2008?

no luck.

telnet 1433

returns connection failed, so I must specify other port.

I tried to use

netstat -abn

but I don't see sqlservr.exe or something similar on this list.

Why it so difficult to find that port? :/

13条回答
等我变得足够好
2楼-- · 2020-01-25 13:33

SQL Server 2000 Programs | MS SQL Server | Client Network Utility | Select TCP_IP then Properties

SQL Server 2005 Programs | SQL Server | SQL Server Configuration Manager | Select Protocols for MSSQLSERVER or select Client Protocols and right click on TCP/IP

查看更多
【Aperson】
3楼-- · 2020-01-25 13:34

try once:-

USE master
DECLARE       @portNumber   NVARCHAR(10)
EXEC   xp_instance_regread
@rootkey    = 'HKEY_LOCAL_MACHINE',
@key        =
'Software\Microsoft\Microsoft SQL Server\MSSQLServer\SuperSocketNetLib\Tcp\IpAll',
@value_name = 'TcpDynamicPorts',
@value      = @portNumber OUTPUT
SELECT [Port Number] = @portNumber
GO
查看更多
兄弟一词,经得起流年.
5楼-- · 2020-01-25 13:39

Here is a quick PowerShell script (since no one has provided solution in PowerShell yet:))

Note: this must be executed at Server (either RDP or use PS Remoting), if ran correctly following will print exact port number:

cls
$id = (ps "sql*" | ? {$_.ProcessName -eq "sqlservr"}).Id
$id | % {
    $strAllSQLConnections = netstat -ano | findstr $_
    $port = $strAllSQLConnections | % { if($_ -match "0\.0\.0\.0:\d{2,5}") {$Matches[0]} }
    $port = ($port -split ':')[1]
    if ($port -gt 0) {Write-Host "An instance of Sql Server is listening on port: " $port}
}

You might need to tweak the code, works great for me.

HTH

查看更多
唯我独甜
6楼-- · 2020-01-25 13:48

If you have run "netstat -a -b -n" (from an elevated command prompt) and you don't see "sqlservr.exe" at all then either your SQL Server service is not running or its TCP/IP network library is disabled.

Run SQL Server Configuration Manager (Start | All Programs | Microsoft SQL Server 2008 | Configuration Tools).

Navigate to SQL Server Services. In the right-hand pane look for SQL Server (). Is it stopped? If so, start it.

Navigate to SQL Server Network Configuration (or SQL Server Network Configuration (32-bit) as appropriate) then Protocols for . In the right-hand pane look for "TCP/IP". Is it disabled? If so, enable it, then restart the SQL Server service.

Note that he Instance ID will be MSSQLSERVER for the default instance.

Please also note that you don't have to enable the TCP/IP network library to connect a client to the service. Clients can also connect through the Shared Memory network library (if the client is on the same machine) or the Named Pipes network library.

查看更多
Emotional °昔
7楼-- · 2020-01-25 13:50

very simple. make a note of the sqlsrvr.exe PID from taskmanager then run this command:

netstat -ano | findstr *PID*

it will show TCP and UDP connections of your SQL server (including ports) standard is 1433 for TCP and 1434 for UDP

example : enter image description here

查看更多
登录 后发表回答