How to find the port for MS SQL Server 2008?

后端 未结 13 1752
广开言路
广开言路 2020-11-29 02:24

I am running MS SQL Server 2008 on my local machine. I know that the default port is 1433 but some how it is not listening at this port. The SQL is an Express edition.

相关标签:
13条回答
  • 2020-11-29 03:11

    I use the following script in SSMS

    SELECT
         s.host_name
        ,c.local_net_address
        ,c.local_tcp_port
        ,s.login_name
        ,s.program_name
        ,c.session_id
        ,c.connect_time
        ,c.net_transport
        ,c.protocol_type
        ,c.encrypt_option
        ,c.client_net_address
        ,c.client_tcp_port
        ,s.client_interface_name
        ,s.host_process_id
        ,c.num_reads as num_reads_connection
        ,c.num_writes as num_writes_connection
        ,s.cpu_time
        ,s.reads as num_reads_sessions
        ,s.logical_reads as num_logical_reads_sessions
        ,s.writes as num_writes_sessions
        ,c.most_recent_sql_handle
    FROM sys.dm_exec_connections AS c
    INNER JOIN sys.dm_exec_sessions AS s
        ON c.session_id = s.session_id
    
    --filter port number
    --WHERE c.local_tcp_port <> 1433
    
    0 讨论(0)
  • 2020-11-29 03:13

    You can use this two commands: tasklist and netstat -oan

    Tasklist.exe is like taskmgr.exe but in text mode.

    With tasklist.exe or taskmgr.exe you can obtain a PID of sqlservr.exe

    With netstat -oan, it shows a connection PID, and you can filter it.

    Example:

    C:\>tasklist | find /i "sqlservr.exe"
    sqlservr.exe  1184 Services    0 3.181.800 KB
    
    C:\>netstat -oan | find /i "1184"
    TCP  0.0.0.0:1280  0.0.0.0:0  LISTENING  1184
    

    In this example, the SQLServer port is 1280

    Extracted from: http://www.sysadmit.com/2016/03/mssql-ver-puerto-de-una-instancia.html

    0 讨论(0)
  • 2020-11-29 03:15

    I came across this because I just had problems creating a remote connection and couldn't understand why setting up 1433 port in firewall is not doing the job. I finally have the full picture now, so I thought I should share.

    First of all is a must to enable "TCP/IP" using the SQL Server Configuration Manager under Protocols for SQLEXPRESS!

    When a named instance is used ("SQLExpress" in this case), this will listen on a dynamic port. To find this dynamic port you have couple of options; to name a few:

    • checking ERRORLOG of SQL Server located in '{MS SQL Server Path}\{MS SQL Server instance name}\MSSQL\Log' (inside you'll find a line similar to this: "2013-07-25 10:30:36.83 Server Server is listening on [ 'any' <ipv4> 51118]" --> so 51118 is the dynamic port in this case.

    • checking registry: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\{MSSQL instance name}\MSSQLServer\SuperSocketNetLib\Tcp\IPAll, for my case TcpDynamicPorts=51118.

      Edit: {MSSQL instance name} is something like: MSSQL10_50.SQLEXPRESS, not only SQLEXPRESS

    Of course, allowing this TCP port in firewall and creating a remote connection by passing in: "x.x.x.x,51118" (where x.x.x.x is the server ip) already solves it at this point.

    But then I wanted to connect remotely by passing in the instance name (e.g: x.x.x.x\SQLExpress). This is when SQL Browser service comes into play. This is the unit which resolves the instance name into the 51118 port. SQL Browser service listens on UDP port 1434 (standard & static), so I had to allow this also in server's firewall.

    To extend a bit the actual answer: if someone else doesn't like dynamic ports and wants a static port for his SQL Server instance, should try this link.

    0 讨论(0)
  • 2020-11-29 03:19

    Click on Start button in Windows.

    Go to All Programs -> Microsoft SQL Server 2008 -> Configuration Tools -> SQL Server Configuration Manager

    Click on SQL Native Client 10.0 Configuration -> Client Protocols -> TCP/IP double click ( Right click select Properties ) on TCP/IP.

    You will find Default Port 1433.

    Depending on connection, the port number may vary.

    0 讨论(0)
  • 2020-11-29 03:20

    This works for SQL Server 2005 - 2012. Look for event id = 26022 in the error log under applications. That will show the port number of sql server as well as what ip addresses are allowed to access.

    0 讨论(0)
  • 2020-11-29 03:24

    You could also look with a

    netstat -abn
    

    It gives the ports with the corresponding application that keeps them open.

    Edit: or TCPView.

    0 讨论(0)
提交回复
热议问题