Ich-Bullet Puen
Ich-Bullet Puen

Reputation: 91

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

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:

Upvotes: 3

Views: 23284

Answers (6)

Ankit Partap
Ankit Partap

Reputation: 1

If you are facing the following error: Connection error in SSMS

then there are two ways.

  1. Make sure that the instance name is correct in the SSMS while creating a connection. Your instance name in SQL Server & SSMS must be the same. Server name: (your-pc-name)(instance-name). Go to "Run" and type a command "services.msc". Then search for SQL Server (instance-name). Use this instance name in the "Server Name".

[In case this method doesn't work]

  1. At the time of installation of the SQL Server, if you choose "Basic" as an option, then remove the instance name from the "Server name". Just use your system name as a server name.

Upvotes: 0

Kirsten
Kirsten

Reputation: 18066

Try using the port number in the connection string instead of the instance name As I explain here

Upvotes: 0

Vijay Vj
Vijay Vj

Reputation: 367

While establishing a connection with your remote server, Try using '\SQLEXPRESS' at the end of your server. Example : "ABCD_server_name\SQLEXPRESS"

Upvotes: 0

you don't have to use .\SQLEXPRESS, all you need to do is to add your SQL express name only and it works for me

<add name="BlogDbContext" connectionString="data source=your name here; initial catalog=CodeFirstDemo; integrated security=True" providerName="System.Data.SqlClient"/>

Upvotes: 0

casperbear
casperbear

Reputation: 121

This is a very generic error and you may have to try a lot to resolve it.

  1. 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:

    • routing to that IP is not configured;
    • SQL Server port is closed on either side or by a firewall in the middle. Maybe those addresses are even routers (not actual database machines) and NAT is not set up for port 1433.
  2. 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 specifying SQLEXPRESS)

  3. 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.

  4. 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.

Upvotes: 4

Cookie Monster
Cookie Monster

Reputation: 646

Try this:

string constring = @"Data Source=137.xx.xx.xxx\\SQLEXPRESS;Initial Catalog=EDI_HR;Integrated Security =True";

Upvotes: 3

Related Questions