Adsense

Monday, November 05, 2007

SQL Server 2005 Error - 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.

You may receive this error when trying to remotely connect to your SQL Server 2005 (or Express) database. (Even when connection remotely from a service running locally, such as an ASP.NET website.) The first thing to check is the most common cause of this error. You must enable Remote Connection manually to SQL Server 2005 installations because they are disabled by default. To do this, check the following.

Enable remote connections for SQL Server 2005

  1. Open the SQL Server Surface Area Configuration tool. (You can find this in your start menu under SQL Server 2005.)
  2. Expand "Database Engine"
  3. Click on "Remote Connections"
  4. Enable Remote Connections (TCP/IP, Named Pipes, or Both)
  5. Click on Service under "Database Engine" and Stop then Start your database for the changes to take affect.

Test your connection now. For most people this will be sufficient to correct the problem. In my case, my company is using a connection string that did not specify the port when connecting to the database. I had just reinstalled Microsoft SQL Server and received this error and didn't want to have to change anything in the project to get it working again. I found that I had to statically set it for the server to SQL Server's default value of 1433. To do this, perform the following.

Set the port to be used with TCP/IP connections

  1. Open the SQL Server Configuration Manager
  2. 2xpand SQL Server 2005 Network Configuration and select "Protocols for YOURDBSERVERNAME"
  3. Right click on "TCP/IP" on the right and choose properties
  4. Click on the "IP Addresses" tab
  5. Set the TCP Port property for the entry with IP Address "127.0.0.1" or any other that you need and click "Apply".

In our case, this fixed the problem and allowed us to use our connection string unmodified.

No comments: