Dynamic port allocation in Microsoft SQL Server 2000 and Microsoft SQL Server 2005

Static port allocation If you configure an instance of SQL Server to use a static port, and you restart the instance of SQL Server, the instance of SQL Server listens only on the specified static port. The SQL Server clients must send all the requests only to the static port where the instance of SQL Server is listening.

However, if an instance of SQL Server is configured to listen on a static port, and another program that is running on the computer is already using the specified static port when SQL Server is started, SQL Server does not listen on the specified static port. 

By default, the default instance of SQL Server listens for requests from SQL Server clients on static port 1433. Therefore, the client network libraries assume that either port 1433 or the global default port that is defined for that client computer is used to connect to the default instance of SQL Server.

If a default instance of SQL Server is listening on a port other than port 1433, you must either define a server alias name or change the global default port by using the Client Network Utility. However, you can also make the default instance of SQL Server listen on multiple static ports.

Dynamic port allocation Only named instances of SQL Server can use the dynamic port allocation process. In the dynamic port allocation process, when you start the instance of SQL Server for the first time, the port is set to zero (0). Therefore, SQL Server requests a free port number from the operating system. As soon as a port number is allocated to SQL Server, SQL Server starts listening on the allocated port.

The allocated port number is written to the Windows registry. Every time that you start that named instance of SQL Server, it uses that allocated port number. However, in the unlikely case that another program that is already running on the computer is using that previously allocated (but not static) port number when you start SQL Server, SQL Server chooses another port.

Verifying the port configuration of an instance of SQL Server

NoteDefault instances of SQL Server always use a static port. 

First verify that your instance of SQL Server has the TCP/IP protocol enabled. Then, to find which TCP/IP port your instance of SQL Server is "listening on", examine the SQL Server error log. Additionally, in SQL Server 2005 and in later versions, you can check settings in the SQL Server Configuration Manager. If you wish to see the SQL error log from within a program, follow these steps.

Note For SQL Server 2000, use Query analyzer to execute the following queries.

1.       Start SQL Server Management Studio, and then connect to the instance of SQL Server.

2.       Run the following query:

3.            Use master Go Xp_readerrorlog

4.       In the Results pane, locate the following text (where X.X.X.X is the IP address of the instance of SQL Server and Y is the TCP/IP port where SQL Server is listening):

SQL server listening on X.X.X.X: Y

Note: For example, if you locate the "SQL server listening on 10.150.158.246: 1433" text in the Results pane, 10.150.158.246 is the IP address of the SQL Server and 1433 is the TCP/IP port where the instance of SQL Server is listening.

To verify the port configuration of an instance of SQL Server, follow these steps:

1.       Start Registry Editor.

2.       In Registry Editor, locate the following registry key:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\<InstanceName>\MSSQLServer\SuperSocketNetLib\Tcp

Note If you are using SQL Server 2005, locate the following registry subkey:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\<MSSQL.x>\MSSQLServer\SuperSocketNetLib\Tcp\IPAll

Notice the TCPDynamicPorts value and the TCPPort value. These values appear as follows, depending on your port allocation method:

o        Static Port Allocation
If you configure an instance of SQL Server to use a static port, and you have not yet restarted the instance of SQL Server, the registry values are set as follows:

TCPDynamicPorts = Last port used
TCPPort = New static port to be used after the next restart; new static port that you set by using the Server Network Utility

However, if you configure an instance of SQL Server to use a static port, and you restart the instance of SQL Server, the registry values are set as follows:

TCPDynamicPorts = Blank
TCPPort = New static port that you set by using the Server Network Utility

o        Dynamic Port Allocation
If you configure an instance of SQL Server to use dynamic port allocation, and you have not yet restarted the instance of SQL Server, the registry values are set as follows:

TCPDynamicPorts = Blank
TCPPort = 0

However, if you configure an instance of SQL Server to use dynamic port allocation, and you restart the instance of SQL Server, the registry values are set as follows:

TCPDynamicPorts = Current port used
TCPPort = Current port used

Configuring an instance of SQL Server to use a static port

SQL Server 2005 and SQL Server 2008

To configure an instance of SQL Server 2005 or SQL Server 2008 to use a static port, follow the steps that are described in the How to: Configure a Server to Listen on a Specific TCP Port (SQL Server Configuration Manager) topic in SQL Server 2005 Books Online or in SQL Server 2008 Books Online.

To configure a static port for the specialized Dedicated Administrator Connection (DAC), you must update the registry key that corresponds to your instance. For example, the registry key may be the following:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.X\MSSQLServer\SuperSocketNetLib\AdminConnection\Tcp

Note The "X" in "MSSQL.X" is a number that indicates the directory where the instance is installed for SQL Server 2005 or the instance name for SQL Server 2008.

SQL Server 2000

To configure an instance of SQL Server to use a static port, follow these steps:

1.       Start the Server Network Utility. To do this, do one of the following:

o        Click Start, point to Programs, point to Microsoft SQL Server, and then click Server Network Utility.

o        Click Start, and then click Run. In the Open box, type svrnetcn.exe, and then click OK.

The Server Network Utility dialog box appears.

2.       In the Server Network Utility dialog box, click the General tab.

3.       In the Instance(s) on this server list, select your instance of SQL Server.
Note If TCP/IP protocol is disabled, enable it now. To do this, click TCP/IP in the Disabled Protocols list, and then click Enable.

4.       In the Enabled Protocols list, click TCP/IP, and then click Properties.

5.       In the Default port box, type a static port number, and then click OK.
Note The static port that you specify must differ from the dynamic port that your instance of SQL Server is currently listening on. For example, if an instance of SQL Server is currently listening on dynamic TCP/IP port 1400, type 1500 for the new static port.

6.       Click OK, and then click OK again.

7.       Restart the instance of SQL Server.

8.       View the SQL Server error logs to verify that the instance of SQL Server is currently using the static port.
Note If you have a clustered instance of SQL Server, and you follow the specified steps on a cluster node, you may notice that the TCPDynamicPorts registry values and the TCPPort registry values on other cluster nodes still hold the old values. When you move the SQL Server group to the corresponding cluster node, and then bring SQL Server online on the cluster node, the registry values on the cluster nodes will reflect the correct values.

You may want to set the static port of your instance of SQL Server to the same port number as the dynamic port that it used earlier. To do this, follow these steps:

1.       View the TCPDynamicPorts registry value and the TCPPort registry value to determine the dynamic port number that the earlier instance of SQL Server used.

2.       In the Server Network Utility, set the static port to a different port number than the registry value that you determined in step 1.

3.       Restart the instance of SQL Server.

4.       In the Server Network Utility, set the static port to the registry value that you determined in step 1.

5.       Restart the instance of SQL Server.

Configuring an instance of SQL Server to use a dynamic port

SQL Server 2005 and SQL Server 2008

To configure your instance of SQL Server 2005 or your instance of SQL Server 2008 to use a dynamic port, use the similar method described in the "How to: Configure a Server to Listen on a Specific TCP Port (SQL Server Configuration Manager)" topic in SQL Server 2005 Books Online or in SQL Server 2008 Books Online. For more information, see the Server Network Configuration topic in SQL Server 2005 Books Online or in SQL Server 2008 Books Online.

SQL Server 2000

To configure your instance of SQL Server to use a dynamic port, follow these steps:

1.       Start the Server Network Utility. To do this, do one of the following:

o        Click Start, point to Programs, point to Microsoft SQL Server, and then click Server Network Utility.

o        Click Start, and then click Run. In the Open box, type svrnetcn.exe, and then click OK.

The Server Network Utility dialog box appears.

2.       In the Server Network Utility dialog box, click the General tab.

3.       In the Instance(s) on this server list, select your instance of SQL Server.
Note If TCP/IP protocol is disabled, enable it now. To do this, click TCP/IP in the Disabled Protocols list, and then click Enable.

4.       In the Enabled Protocols list, click TCP/IP, and then click Properties.

5.       In the Default port box, type 0, and then click OK.

6.       Click OK, and then click OK again.

7.       Restart the instance of SQL Server.

8.       View the SQL Server error logs to verify that the instance of SQL Server is currently using the dynamic port.

Troubleshooting

If the SQL Server clients cannot access an instance of SQL Server after you have configured it to use a static TCP/IP port, the following causes may exist:

  • A firewall may be blocking the specified TCP/IP port.
    If the port that the SQL Server instance is currently listening on is blocked by your firewall, the connections will fail. For information about how to configure your firewall to work with your SQL Server, please see the Configuring the Windows Firewall to Allow SQL Server Access topic in SQL Server 2008 Books Online. Although this topic is specific to SQL Server 2008, most of the information applies to SQL Server 2005 and SQL Server 2000.
    For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:

287932  (http://support.microsoft.com/kb/287932/ ) TCP ports needed for communication to SQL Server through a firewall

318432  (http://support.microsoft.com/kb/318432/ ) BUG: Cannot connect to a clustered named instance through a firewall

968872  (http://support.microsoft.com/kb/968872/ ) How do I open the firewall port for SQL Server on Windows Server 2008?

Another program may already be using the specified TCP/IP port.
If another program is already using the specified TCP/IP port, the port is not available to the instance of SQL Server and SQL Server clients may be unable to connect to the instance of SQL Server.
This problem is specific to an instance of SQL Server that is configured to use a static TCP/IP port. This problem does not occur for an instance of SQL Server that is configured to use dynamic port allocation. In dynamic port allocation, if another program is already using the specified TCP/IP port when you start the instance of SQL Server, the instance of SQL Server selects a new port.

      Note If you have a clustered instance of SQL Server, and you follow the specified steps on a cluster node, you may notice that the TCPDynamicPorts registry values and the TCPPort registry values on other cluster nodes still hold the old values. When you move the SQL Server group to the corresponding cluster node, and then bring SQL Server online on the cluster node, the registry values on the cluster nodes will reflect the correct values.

Ebook Download
View all
Learn
View all