You are currently offline, waiting for your internet to reconnect

Your browser is out-of-date

You need to update your browser to use the site.

Update to the latest version of Internet Explorer

How to use a script to programmatically open ports for SQL Server to use on systems that are running Windows XP Service Pack 2

Extended support for SQL Server 2005 ends on April 12, 2016

If you are still running SQL Server 2005 after April 12, 2016, you will no longer receive security updates and technical support. We recommend upgrading to SQL Server 2014 and Azure SQL Database to achieve breakthrough performance, maintain security and compliance, and optimize your data platform infrastructure. Learn more about the options for upgrading from SQL Server 2005 to a supported version here.

INTRODUCTION
Microsoft Windows XP Service Pack 2 (SP2) includes Windows Firewall. Windows Firewall is an enhanced version of Internet Connection Firewall (ICF). By default, Windows Firewall is enabled on computers that are running Windows XP Service Pack 2. Windows Firewall will block some network connections that use TCP/IP, that use Named Pipes, or that use Multiprotocol Remote Procedure Call (RPC). This blocking can affect Microsoft Data Engine (MSDE), Microsoft SQL Server 2000, and Microsoft SQL Server 2005.

If you have an application that requires SQL Server or MSDE to have access to the network by using Named Pipes, by using TCP/IP, or by using RPC, you can use the scripts that are provided in the "More Information" section to open the required ports programmatically instead of using Windows Firewall.

Two scripts are included in this article. The first script programmatically configures Windows Firewall to allow SQL Server to listen on the network on all protocols. The second script programmatically configures Windows Firewall to allow SQL Server to listen on TCP/IP only.

Note We recommend that you open ports on an as-needed basis only.


The scripts that are discussed in this article provide Multiprotocol (RPC) over Named Pipes access only. If you are running RPC over TCP, see the following Microsoft Knowledge Base article for information about using TCP/IP:
841252 How to manually enable TCP/IP on Windows XP Service Pack 2 for SQL Server 2000
MORE INFORMATION

A script that you can use to open all ports

The script that is discussed in this section programmatically configures Windows Firewall to allow SQL Server to listen on the network on all protocols.

Important notes about this script
  • This script should only be run on computers that are running Windows XP Service Pack 2.
  • This script has additional options for enabling Named Pipes and for enabling Multiprotocol (RPC).
  • This script enables Multiprotocol (RPC) only over Named Pipes and only opens port 445.
  • This script does not provide functionality to specify scope.

To create the script, follow these steps:
  1. Start Notepad.
  2. Copy and paste the following code into Notepad:
    echo offif "%1"=="-np" goto HandleNpif "%1"=="-rpc" goto HandleRpcif "%1"=="-tcp" goto HandleTcpif "%1"=="-browser" goto HandleBrowserrem Usage:Usageecho "Usage: setupSqlServerPortAll -[np | rpc | tcp | browser] -port [portnum] -[enable | disable]echo "-np : Setup SQLServer to listen on Named Pipe connections for local subnet only"echo "-rpc : Setup SQLServer to listen on RPC multiprotocol for local subnet only"echo "-tcp : Setup SQLServer to listen on TCP connections for local subnet only"echo "       Must specify a port if -tcp option is chosen."echo "-browser :  Setup SQLServer to provide SSRP service to support named instances"echo "-port : Applies only for tcp"echo " One of the following options MUST be specified"echo "-enable: Enables a port"echo "-disable: Disables a port"goto Exit:HandleTcpecho %2if "%2"=="-port" goto contgoto Usage:contif "%3"=="" goto Usageif "%4"=="-enable" goto EnableTcpif "%4"=="-disable" goto DisableTcpgoto Usage:EnableTcpecho "Enabling SQLServer tcp access for port %3 local subnet only"netsh firewall set portopening tcp %3 SQL%3 ENABLE subnetgoto Exit:DisableTcpecho Disabling SQLServer tcp access for port %3 local subnet only"netsh firewall set portopening tcp %3 SQL%3 disable subnet goto Exit:HandleNpif "%2"=="-enable" goto EnableNpif "%2"=="-disable" goto DisableNpgoto Usage:EnableNpecho "Enabling SQLServer named pipe access for local subnet only"netsh firewall set portopening tcp 445 SQLNP ENABLE subnetgoto Exit:DisableNpecho Disabling SQLServer named pipe access for local subnet only"netsh firewall set portopening tcp 445 SQLNP DISABLE subnetgoto Exit:HandleRpcif "%2"=="-enable" goto EnableRpcif "%2"=="-disable" goto DisableRpcgoto Usage:EnableRpcecho "Enabling SQLServer multiprotocol access for local subnet only"netsh firewall set portopening tcp 445 SQLNP enable subnetgoto Exit:DisableRpcecho Disabling SQLServer multiprotocol access for local subnet only"netsh firewall set portopening tcp 445 SQLNP disable subnetgoto Exit:HandleBrowserif "%2"=="-enable" goto EnableBrowserif "%2"=="-disable" goto DisableBrowsergoto Usage:EnableBrowserecho "Enabling SQLServer SSRP service for local subnet only"netsh firewall set portopening udp 1434 SQLBrowser enable subnetgoto Exit:DisableBrowserecho "Enabling SQLServer SSRP service for local subnet only"netsh firewall set portopening udp 1434 SQLBrowser disable subnetgoto Exit:Exitendlocal
  3. Save the file as a .txt file, and name the file ConfigSQLPorts.txt.
  4. Rename the ConfigSQLPorts.txt file to ConfigSQLPorts.bat.

When you run the script in the ConfigSQLPorts.bat file, you must use the computer that the script is saved on. To run the script, follow these steps:
  1. Click Start, click Run, type cmd, and then click OK.
  2. In the command window, use the "cd" command to change folders until you are in the same folder that the ConfigSQLPorts.bat file is saved in. For example, if the ConfigSQLPorts.bat file is saved in C:\Myfiles, you would type CD myfiles at the command prompt, and then press ENTER. This will change your folder to C:\Myfiles.
  3. To run the ConfigSQLPorts.bat script, type ConfigSQLPorts.bat at the command prompt, and then press ENTER.




A script that you can use to open only TCP/IP ports

The script that is discussed in this section configures Windows Firewall to allow SQL Server to listen on TCP/IP only.

To create the script, follow these steps:
  1. Start Notepad.
  2. Copy and paste the following code into Notepad:

    echo offsetlocalif "%1"=="-port" goto HandleTcprem Usage:Usageecho "Usage: setupSqlServerPort -port [portnum] -[enable | disable] [ALL | SUBNET]"echo -port : Specifies the port to be enabled or disabled. Port is not optional.echo -enable: Enables a portecho -enable ALL:  enables access for ALLecho -enable SUBNET:  enables access for SUBNETecho -disable: Disables a portecho  one of -enable or -disable must be specifiedecho  the default scope is SUBNET onlygoto Exit:HandleTcpif "%2"=="" goto Usageif "%3"=="-enable" goto EnableTcpif "%3"=="-disable" goto DisableTcpgoto Usage:EnableTcpset SCOPE="%4"if "%4"=="ALL" echo "Enabling SQLServer tcp access for port %2 ALL access" if "%4"=="SUBNET" echo "Enabling SQLServer tcp access for port %2 subnet only access"if "%4"=="" set SCOPE="SUBNET"netsh firewall set portopening tcp %2 SQL_PORT_%2 ENABLE %SCOPE%goto Exit:DisableTcpecho Disabling SQLServer tcp access for port %2"netsh firewall set portopening tcp %2 SQL_PORT_%2 disable goto Exit:Exitendlocal
  3. Save the file as a .txt file, and name the file SetupSqlServerPort.txt.
  4. Rename the SetupSqlServerPort.txt file to SetupSqlServerPort.bat.


When you run the SetupSqlServerPort.bat script, you must use the computer that the script is saved on. To run the script, follow these steps:
  1. Click Start, click Run, type cmd, and then click OK.
  2. In the command window, use the "cd" command to change folders until you are in the same folder that the SetupSqlServerPort.bat file is saved in. For example, if the SetupSqlServerPort.bat file is saved in C:\Myfiles, you would type CD myfiles at the command prompt, and then press ENTER. This will change your folder to C:\Myfiles.
  3. To run the SetupSqlServerPort.bat script, at the command prompt type setupSqlServerPort.bat, and then press ENTER.


REFERENCES
For additional information about configuring SQL Server 2000 and Windows XP Service Pack 2, click the following article number to view the article in the Microsoft Knowledge Base:
841249 How to configure Windows XP Service Pack 2 (S) for use with SQL Server
springboard script connect error
Properties

Article ID: 839980 - Last Review: 01/11/2006 21:34:09 - Revision: 3.5

  • Microsoft SQL Server 2000 Desktop Engine (Windows)
  • Microsoft SQL Server 7.0 Standard Edition
  • Microsoft SQL Server, Desktop Edition
  • Windows XP Embedded
  • Microsoft SQL Server 2005 Standard Edition
  • Microsoft SQL Server 2005 Developer Edition
  • Microsoft SQL Server 2005 Enterprise Edition
  • Microsoft SQL Server 2005 Express Edition
  • Microsoft SQL Server 2005 Workgroup Edition
  • Microsoft SQL Server 2000 Standard Edition
  • kbfirewall kbinfo KB839980
Feedback
')[0].appendChild(m);" onload="var m=document.createElement('meta');m.name='ms.dqp0';m.content='false';document.getElementsByTagName('head')[0].appendChild(m);" src="http://c1.microsoft.com/c.gif?"> >>ript' src='" + (window.location.protocol) + "//c.microsoft.com/ms.js'><\/script>");