.NET C# Java Javascript Exception


The problem

“Cannot connect to sql\instance. 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) (Microsoft SQL Server, Error: -1)”

Let’s say we have a system with a running SQL Server (Express or Standard Edition - doesn’t matter) and want to connect to this database from another machine. The chances are high that you will see the above error message.

Be aware: You can customize more or less anything, so this blogposts does only cover a very “common” installation.

I struggled last week with this problem and I learned that this is a pretty “old” issue. To enlighten my dear readers I made the following checklist:


  • Does the SQL Server allow remote connections?
  • Does the SQL Server allow your authentication schema of choice (Windows or SQL Authentication)?
  • Check the “SQL Server Configuration Manager” if the needed TCP/IP protocol is enabled for your SQL Instance.
  • Check if the “SQL Server Browser”-Service is running
  • Check your Windows Firewall (see details below!)
  • This is a weird one, but try to add the Port to the ConnectionString, e.g. Data Source=MyServer\Instance,1434. This is not always needed, but I had one case, where each point on this list was OK, but I couldn’t connect from a client without the port.

Windows Firewall settings:

Per default SQL Server uses TCP Port 1433 which is the minimum requirement without any special needs - use this command:

netsh advfirewall firewall add rule name = SQLPort dir = in protocol = tcp action = allow localport = 1433 remoteip = localsubnet profile = DOMAIN,PRIVATE,PUBLIC

If you use named instances we need (at least) two additional ports:

netsh advfirewall firewall add rule name = SQLPortUDP dir = in protocol = udp action = allow localport = 1434 remoteip = localsubnet profile = DOMAIN,PRIVATE,PUBLIC

This UDP Port 1434 is used to query the real TCP port for the named instance.

Now the most important part: The SQL Server will use a (kind of) random dynamic port for the named instance. To avoid this behavior (which is really a killer for Firewall settings) you can set a fixed port in the SQL Server Configuration Manager.

SQL Server Configuration Manager -> Instance -> TCP/IP Protocol (make sure this is "enabled") -> *Details via double click* -> Under IPAll set a fixed port under "TCP Port", e.g. 1435

After this configuration, allow this port to communicate to the world with this command:

netsh advfirewall firewall add rule name = SQLPortInstance dir = in protocol = tcp action = allow localport = 1435 remoteip = localsubnet profile = DOMAIN,PRIVATE,PUBLIC

(Thanks Stackoverflow!)

Check the official Microsoft Docs for further information on this topic, but these commands helped me to connect to my SQL Server.

The “dynamic” port was my main problem - after some hours of Googling I found the answer on Stackoverflow and I could establish a connection to my SQL Server with the SQL Server Management Studio.

Hope this helps!

.net web csharp asp.net javascript html5 asp.net-mvc jquery css iis
Weitere News:
5 Meinungen
Thank you for this. Stack has been a fair bit of confusion for me.michaels worksmart
A SQL Server port can be identified with an occasion level and is explicit for that case. Ports are utilized by SQL Server when an occasion is designed to utilize the TCP/IP convention. At the point when system Michael Black Jacket information/association solicitation lands at your server machine through the IP address and case name, now SQL Server gets information on its particular port
Custom Term Paper Service industry has grown steadily in provision of Legitimate Term Paper Services and high quality Custom Term Paper Writing Services which is preferred by scholars worldwide.
Such a nice forum topic discussion, The majority of students think that doing their homework is boring. They do everything accept their homework. If you are one of such students, struggling with the study overload and burden of the assignment.
Speedycoursework writing service to apply for help.
My name is Elle Ford, I am a fashion blogger and I also own an online store named "BuyMovie Jackets" where we sell all kinds of stylish leather jackets, coats, and vests worn by celebrities in any of their shows, movies, etc.
Schreibe einen Kommentar:
iis css jquery asp.net-mvc html5 javascript asp.net csharp web .net
Entweder einloggen... ...oder ohne Wartezeit registrieren
Passwort wiederholen