January 2, 2013

A network-related or instance-specific error occurred while establishing a connection to SQL Server

This error comes when you are unable to pass correct credentials from application to connect with database. There are many different ways to connect your application with database server. Some times this error comes when you pass wrong userId and password to database or you are trying to access database server through LAN.

During trying to access database server through LAN, there are many things mess up.

  1. Wrong userId and password
  2. Ping interval breaking
  3. System is shutdown etc
To resolve this issue, make sure your following steps are in working condition correctly
  • Database Engine is configured correctly to accept remote connections
Make sure your database engine is configured to accept remote connections. To Enable remote connections do following things. 
  1. Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration
  2. Click on Surface Area Configuration for Services and Connections
  3. Select the instance that is having a problem > Database Engine > Remote Connections
  4. Enable local and remote connections
  5. Restart instance

  • SQL Server Service account

If you are not using a domain account as a service account and you are using NETWORK SERVICE, you may want to switch this first before proceeding.
  • SQL Server Instance
If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings in your application. Usually the format needed to specify the database server is machinename\instancename. Check your connection string as well
  • Firewall Exception
You may need to create an exception on the firewall for the SQL Server instance and port you are using:
  1. Start > Run > Firewall.cpl
  2. Click on exceptions tab
  3. Add the sqlservr.exe (typically located in C:\Program Files (x86)\Microsoft SQL Server\MSSQL.x\MSSQL\Binn, check your installs for the actual folder path), and port (default is 1433)
  4. Check your connection string as well
Also you may also need to create an exception in your firewall for SQL Browser.