Error Has Occurred While Establishing A Connection To SQL Server 2005 Which Does Not Allow Local and Remote Connections
When connecting to an instance of Microsoft SQL Server 2005 database, including SQL Server 2005 Express, Developer and Enterprise editions, for authentication or accessing and retrieving and updating the data, the the following error message may appear. The problem happens no matter the connection is originated from remote computer or on SQL Server local computer itself, and can be caused by any program, such as SQLCMD utility, used to connect to SQL Server.
Sqlcmd: Error: Microsoft SQL Native Client: An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections.
Or,
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 2)
This problem may occur when SQL Server 2005 is not configured to accept incoming local and remote connections, which is disabled by default in SQL Server 2005 Express Edition, SQL Server 2005 Developer Edition and also SQL Server 2005 Enterprise Edition. To solve the connection forbidden problem, SQL Server 2005 needs to configure to allow incoming local and remote connections.
Firstly, ensure that SQL Server 2005 is configured properly to allow incoming connections on the instance of database server, else enable and turn on the local and remote connections setting.
- Click Start button, then go to Programs or All Programs, then select Microsoft SQL Server 2005, followed by Configuration Tools. Click and run the SQL Server Surface Area Configuration.
- On the “SQL Server 2005 Surface Area Configuration” page, click Surface Area Configuration for Services and Connections.
- On the “Surface Area Configuration for Services and Connections” page, expand Database Engine tree, click Remote Connections.
- Select Local and remote connections, or Local connections only which applicable only if there is no remote system tries to connect to the SQL Server, useful when you just trying to connect and authenticate with the server after installing.
- Select the appropriate protocol to enable to local and/or remote connections environment. To ensure maximum compatibility, select Using both TCP/IP and named pipes.
- Click Apply button when done.
- Click OK button when prompted with the message saying that “Changes to Connection Settings will not take effect until you restart the Database Engine service.”
- On the “Surface Area Configuration for Services and Connections” page, expand Database Engine, then click Service.
- Click Stop button to stop the SQL Server service.
- Wait until the MSSQLSERVER service stops, and then click Start button to restart the MSSQLSERVER service.
Secondly, SQL Server Browser service has to be enabled to allow for local and remote connections if SQL Server 2005 is running by using an instance name and users are not using a specific TCP/IP port number in the connection string.
- Click Start button, then go to Programs or All Programs, then select Microsoft SQL Server 2005, followed by Configuration Tools. Click and run the SQL Server Surface Area Configuration.
- On the “SQL Server 2005 Surface Area Configuration” page, click Surface Area Configuration for Services and Connections.
- On the “Surface Area Configuration for Services and Connections” page, click SQL Server Browser.
- Select Automatic as the Startup type to start SQL Server Browser service automatically every time system starts.
- Click Apply button.
- Click on Start button to start the service immediately.
- Click OK button.
Finally, if remote computer needs to connect and access SQL Server, an exceptions in Windows Firewall included in Windows XP SP2 (Service Pack 2), Windows Server 2003 and Windows Vista needs to be created. If you’re using third-party firewall system, the exception rules also needed to be created to allow external remote connections to the SQL Server 2005 and SQL Server Browser Service to communicate through the firewall, else connections will be blocked. Consult the firewall manual for more details. Each instance of SQL Server 2005 must have its own exception, together with an exclusion for SQL Server Browser service.
SQL Server 2005 uses an instance ID as part of the path when you install its program files. To create an exception for each instance of SQL Server, you must identify the correct instance ID. To obtain an instance ID, follow these steps:
- Click Start button, then go to Programs or All Programs, then select Microsoft SQL Server 2005, followed by Configuration Tools. Click and run the SQL Server Configuration Manager.
- In “SQL Server Configuration Manager”, click the SQL Server Browser service in the right pane, right-click the instance name in the main window, and then click Properties.
- On the “SQL Server Browser Properties” page, click the Advanced tab, locate the instance ID in the property list.
- Click OK button.
Then create an exception for SQL Server 2005 in Windows Firewall.
- Click on Start button, the click on Run and type firewall.cpl, and then click OK. For Windows Vista, type firewall.cpl in Start Search box and press Enter key, then click on Allow a program through Windows Firewall link on left tasks pane.
- In “Windows Firewall”, click the Exceptions tab, and then click Add Program.
- In the “Add a Program” window, click Browse button.
- Click the C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe executable program, click Open button. MSSQL.1 with is a placeholder for the instance ID that is obtained from previous procedure. Note that the path may be different depending on where SQL Server 2005 is installed.
- Click OK button.
- Repeat steps 1 through 5 for each instance of SQL Server 2005 that needs an exception.
- For SQL Server Browser service, locate the C:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe executable program, and click Open button.
- Click OK button.
Related Articles
- Workaround for Remote Desktop Client to Connect to Localhost (Local Terminal Server Service)
- Connect to Remote Computer using Specific Non Standard Port using Remote Desktop Connection Client
- Vista Remote Desktop Connection Client Slow Delay or Disconnect When Connect to Windows Server 2003 SP2 x64 Edition RDP
- Easily Maintain Multiple Remote Desktop Connections with visionapp Remote Desktop (vRD)
- Enable Multiple Concurrent Remote Desktop Connections or Sessions in Windows XP
- Remote Connections Manager for RDP, VNC, SSH, RLogin and More mRemote Free Download
- Remote Desktop Connection (RDP) Client 6.0 for Windows XP and 2003
- Uninstall and Remove Multiple Database Instances of Microsoft SQL Server 2005
- Microsoft Virtual Server 2005 R2 SP1 (Enterprise Edition) Direct Download Links
- Microsoft Virtual Server 2005 R2 Download Available for Free










































May 16th, 2009 04:11
i get the same problem with godaddy.com hosting
dn you know how i solved it on godaddy ?
March 25th, 2009 21:02
I am trying to connect a sql server 2005 instance installed on XP SP2 from a sql server 2005 express edition on vista.
I’v done all the changes on both the machines, but my vista machine still does not connect with the sql instance on XP.
what could be the issue here ?
March 20th, 2009 17:21
Thanks for your help…
It solved my problem..
It was really very useful
March 11th, 2009 15:51
Thanks. It solved my problem.
Great article
March 4th, 2009 21:25
men tengo un problema! yo uso el mumaker! y cuando establesco una conex remota! para el sql q lo tengo en el servidor en otra pc me sale ese mismo error! en esta pc donde tengo el maker no tengo ningun sql instalado solo los net.framework del 2.0 al 3.5 y aun asi me sale el error del sql 2005 cuando no lo tengo aqui e incluso en la pc donde tengo el server uso el sql 2003! no entiendo la vdd? crees q sea mi so? xq en esta pc tengo un skin el illuusion v2 y enla otra donde tengo el server el xp s2! espero tu pronta y grata respuesta
March 3rd, 2009 12:34
ขอบคุณมากจ้าาา (Thailand)
February 25th, 2009 04:54
Thanks for the detailed explanation and step by step guide for connection problem
February 25th, 2009 04:52
Thanks for detailes explanation on this very common and frequently faced problem by sql developers.
February 14th, 2009 00:32
Thank you very much… Very useful solution.
February 10th, 2009 04:13
simply superb! Thanks a lot.
February 2nd, 2009 11:54
GREAAATT succESS!
December 3rd, 2008 20:14
I restarted the service from services menu, for some reason that did not work. Your solution worked perfectly. Thanks.
November 20th, 2008 00:57
for some reason this solution is working for me.
November 12th, 2008 09:26
看了,好像没什么帮助
October 30th, 2008 23:47
thanks a lot, helped me so much
October 20th, 2008 18:45
It’s Fabulous,
Thank You!
October 14th, 2008 02:48
Muuuuchas Gracias
July 22nd, 2008 23:16
Thanks! Your solution worked fine for me! Appreciate all the help!
April 17th, 2008 02:34
Thank you for this. Very useful.