I'm newbie developer. I have a problem trying to connect to SQL Server from my computer to server machine.
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)
I've searched the way to issue it and I'm found many solution. But none are working for me. Could you please help me?
This is my connection string
string constring = @"Data Source=137.xx.xx.xxx\\SQLEXPRESS;Initial Catalog=EDI_HR;User ID=sa;Password=1234;";
and
string constring = @"Data Source=CISXXXXXX\SQLEXPRESS;Initial Catalog=EDI_HR;User ID=sa;Password=1234;";
Finally, those are some of the references of a solution that don't work for me:
- https://www.lansweeper.com/kb/174/a-network-related-or-instance-specific-error-occurred.html
- https://support.solarwinds.com/Success_Center/Network_Performance_Monitor_(NPM)/Exception_A_network_related_or_instance_specific_error_while_establishing_a_connection_to_SQL_Server
- Why am I getting "Cannot Connect to Server – A network-related or instance-specific error"?
- Why did a network-related or instance-specific error occur while establishing a connection to SQL Server?
Best Answer
This is a very generic error and you may have to try a lot to resolve it.
Check connection from application machine to database machine. Open command line and first try to use ping and telnet "ping 137.xx.xx.xxx", "ping CISXXXXXX", "telnet 137.xx.xx.xxx 1433", "telnet CISXXXXXX 1433". If you have no connection then there are two main possibilities:
Go to the remote machine and try to connect to SQL Server instance named
SQLEXPRESS
locally (using SSMS). If you cannot perhaps it's not started. Or maybe there is no named instance and you need to connect to default instance (i.e. without specifyingSQLEXPRESS
)Check that SQL Server instance allows remote connections through TCP/IP. I guess the easiest way to do it is to go to the remote machine and open SQL Server Configuration Manager.
Check symbols in your connection strings. I see that one of your connection strings has double back slash and another has single back slash. That's suspicious. If you start C# string literal from @ then you should use single back slash.
There are other possibilities, but I think you got the idea.