A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)



SQL Server exception message

I have seen many developers facing the above error on forums, hence I decided to explain the causes of the same.

Below is a Sample connection string

<connectionStrings>

    <add name="conString"

       connectionString="Data Source=MCN-1\SQLExpress;

                         database=Northwind;

                         Integrated Security=true" />

</connectionStrings>

 

The error simply states that it is not able to locate the SQL Server Instance in above connection string (\SQLExpress). One of the causes of this error comes in the incorrect connection string due to misspelled names of server of instances.

Mainly one should check.

1. Data Source or Server Name or IP address is Correct. For example here MCN-1

2. If any instance used check whether the instance name is correct. For example here SQLExpress

3. If any remote connections check if there is some firewall installed if yes disable it.

4. Also check if remote connections are configured in SQL Server. To configure SQL Server to allow   remote connections read here. This article also explains how to create an exception in firewall in order to allow remote connections.

5. If it’s a remote server check if you are able to connect to the server or not. Try pinging to the server. Make sure your machine is connected to the server through LAN or internet.

 

Finally also make sure that the SQL Server Browser service is running on the system. If it is stopped start it

The above helped me solve my issue. If someone else has anything other than above please feel free to share.