71

I'm very frustrated. I have a website running on Visual Web Developer 2008 Express with my local database, everything works great. I also have the same web site running on a production server. Everything was working great but tonight I did a "reset" on production.

  1. I deleted a couple of table, re-created them and inserted data. Everything was ok at this time.

  2. I deleted ALL the files via the FTP.

  3. I used the module called "Copy website" in visual studio and copy the site to the website via FTP.

When I log on my website, here is the error I got:

Server Error in '/' Application.

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)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: 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)


Nothing has changed related to SQL connection, this is OLD code that I always used. My website is completely paralysed because of this and I feel sick inside because I feel there is nothing I can do.

Can anyone help me please?

one noa
  • 345
  • 1
  • 3
  • 10
Jean-François Côté
  • 4,200
  • 11
  • 52
  • 88
  • Can you connect to the SQL server from another machine? Have you accidentally shut it down? – Preet Sangha Sep 08 '09 at 01:14
  • I get the same error while trying to connect with my SQL management studio. In fact, I never tried that before so I don't know if it's a new behavior or if it's the same thing. This is a production server so I don't know if my sql server is shut down. All I know is that from the web panel, I can access the content of my database without problem... – Jean-François Côté Sep 08 '09 at 01:34
  • I would suggest that you sql server is either shut down, or perhaps there is new firewall etc in the way. My suggestion would be to first reboot the sql server box. Then if this continues check with you infrastructure people to see if the SQL server is up and running and accessible from other computers. – Preet Sangha Sep 08 '09 at 02:08
  • I have solved it by following the troubleshoot steps here: https://learn.microsoft.com/en-us/sql/database-engine/configure-windows/troubleshoot-connecting-to-the-sql-server-database-engine?view=sql-server-2017 – Yusril Maulidan Raji May 30 '18 at 09:32
  • **For Code Migrations** (`update-database` et al) [see this answer](https://stackoverflow.com/a/31266905/3258851). – Marc.2377 Jul 31 '18 at 21:16
  • Related posts - [Why am I getting “Cannot Connect to Server - A network-related or instance-specific error”?](https://stackoverflow.com/q/18060667/465053) & [How do I fix the error 'Named Pipes Provider, error 40 - Could not open a connection to' SQL Server'?](https://stackoverflow.com/q/9945409/465053) – RBT Aug 30 '19 at 08:39

15 Answers15

53

Your connection string was probably overriden when you copied your new website version on the server. Please check the connection string in web.config and see if it is valid.

Johannes Rudolph
  • 35,298
  • 14
  • 114
  • 172
  • 3
    In fact, I was using Visual Studio 2005 before and was doing a "Publish to website". What I didn't know was that in the process, Visual studio put the site in debug mode = false juste before compiling. Now that I have Visual Web developper 2008 express and use the copy to web site instead, that was not done. Since my connexion string is based on "Are we on debug or not", it was trying to connect to my dev server ! Thanks! – Jean-François Côté Sep 08 '09 at 10:45
  • **Other solution, using services** check [this](http://stackoverflow.com/a/35442130/2218697), hope helps. – Shaiju T Oct 25 '16 at 07:41
  • **For Code Migrations** (`update-database` et al) [see this answer](https://stackoverflow.com/a/31266905/3258851). – Marc.2377 Jul 31 '18 at 21:16
43

If you are connecting from Windows Machine A to Windows Machine B (server with SQL Server installed) and are getting this error, you need to do the following:

On Machine B:

  1. Turn on the Windows service called "SQL Server Browser" and start the service Windows Services
  2. In Windows Firewall:
    • enable incoming port UDP 1434 (in case SQL Server Management Studio on machine A is connecting or a program on machine A is connecting)
    • enable incoming port TCP 1433 (in case there is a telnet connection) Windows firewall
  3. In SQL Server Configuration Manager:
    • enable TCP/IP protocol for port 1433 Sql Server Configuration Manager
KyleMit
  • 30,350
  • 66
  • 462
  • 664
JustBeingHelpful
  • 18,332
  • 38
  • 160
  • 245
14

I've resolved the issue. It was due to the SQL browser service.

Solution to such problem is one among below -

  • Check the spelling of the SQL Server instance name that is specified in the connection string.

  • Use the SQL Server Surface Area Configuration tool to enable SQL Server to accept remote connections over the TCP or named pipes protocols. For more information about the SQL Server Surface Area Configuration Tool, see Surface Area Configuration for Services and Connections.

  • Make sure that you have configured the firewall on the server instance of SQL Server to open ports for SQL Server and the SQL Server Browser port (UDP 1434).

  • Make sure that the SQL Server Browser service is started on the server.

link - http://www.microsoft.com/products/ee/transform.aspx?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=-1

Jean-François Côté
  • 4,200
  • 11
  • 52
  • 88
Jayesh Amarnani
  • 141
  • 1
  • 2
  • SQL Server Browser was disabled for me, not sure why it is shipped like this out of the box but that did the trick, thanks. – Nick May 09 '13 at 18:58
  • This problem is odd ... I'm getting the MS Sql Server connection exception but I'm set up using MySql. Connections work in unit testing. – IAbstract May 27 '16 at 05:43
  • Hey! Your suggestion of allowing UDP 1434 on the windows firewall on the host computer helped solve our issue. We also allowed the TCP 1433 port in the firewall. Though your answer is 13 years old, it solved our problem in 2023 ! Thank you! – anacron Jun 05 '23 at 05:16
4

check forthe followings :

Make sure your database engine is configured to accept remote connections

• Start > All Programs > SQL Server 2005 > Configuration Tools > SQL Server Surface Area Configuration • Click on Surface Area Configuration for Services and Connections • Select the instance that is having a problem > Database Engine > Remote Connections • Enable local and remote connections • Restart instance

  1. Check the SQL Server service account

• If you are not using a domain account as a service account (for example if you are using NETWORK SERVICE), you may want to switch this first before proceeding

  1. If you are using a named SQL Server instance, make sure you are using that instance name in your connection strings in your ASweb P.NET application

• Usually the format needed to specify the database server is machinename\instancename • Check your connection string as well

  • Changing "localhost" in my connection string to the SQL Server instance name worked. Correct instance was "PCNAME\SQLEXPRESS". – SushiGuy Nov 26 '13 at 18:53
4

the cause is that SQL SERVER is stopped from services.msc a solution for this problem could be starting SQL SERVER from services.msc

enter image description here

André Abboud
  • 1,864
  • 2
  • 14
  • 23
3

I recently had this problem and it ended up being a port issue. My production SQL Server was set up at to be port 1427 instead 1433.

Just change the connection string to be

...data source=MySQLServerName,1427;initial catalog=MyDBName...

Hope this helps anyone who might be seeing this same issue.

Jeff Johnson
  • 1,095
  • 10
  • 15
2

we have to enable TCP/IP property in sql server configuration manager

2

If your server was working and suddenly started erroring out, your server/instance stopped and connection settings were changed somehow.

For SQL Server 2008 here is how you can fit this:

  1. Goto Start > All Programs > SQL Server 2008 > Configuration Tools > SQL Server Configuration Manager > SQL Server Services.
    And here you'll see all the instances and their state.
  2. The state of the instance you were trying to connect can be stopped here.
  3. Double click on the instance and then click on connect.
  4. It will connect and now go back and run your application, you will be able to connect with no error.

This solution assumes the error is not being caused by something wrong in your connection string.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Agasani
  • 21
  • 2
2

I had the same problem with SQL Server 2008 R2 and when I checked "SQL Server Configuration Manager" My SQL Server instance had Stopped. Right Clicking and Starting the Instance solved the issue.

Safraz
  • 33
  • 4
1

I had same problem regarding that i.e A network-related or instance-specific error occurred while establishing a connection to SQL Server.

I was using SQL Server 2005 (.\sqlexpress)` and worked fine but suddenly services stopped and gave me error.

I solved it like this,

Start -> Search Box - > Sql Configuration Manager -> SQL Server 2005 Services >and just Change Your SQL Server (SQLEXPRESS) State to Running by right clicking that service Sate.

naveen
  • 53,448
  • 46
  • 161
  • 251
mack28
  • 129
  • 2
  • 7
  • 20
1

In my case it was a very silly error. I was using a library to read the connection string out of a config file, and I forgot to double back slash.

For example I had: localhost\sqlexpress which was read as localhostsqlexpress when I should rather have had localhost\\sqlexpress note the \

Zapnologica
  • 22,170
  • 44
  • 158
  • 253
1

I solved this issue by running the following command in an elevated command prompt as specified in this post.

net start mssqlserver
Ashin
  • 386
  • 4
  • 8
0

My remote sql server was expecting connection at a different port and not on the default 1443.

The solution was to add a "," after your sql server IP and then add your port like so 129.0.0.1,2995 (Check the " , " after server IP)

Please find the image for reference below.

enter image description here

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Abdullah Khan
  • 12,010
  • 6
  • 65
  • 78
0

I had the same problem but found that it was because the password for my Service Account for the Database Engine had expired. The solution was to login to that account, fix this, then set the account so password never expires.

Mister Cook
  • 1,552
  • 1
  • 13
  • 26
-1

I had the same error, and it turned out .NET created a database on localhost which I wasn't aware of. When I tried to get the site live it didn't create the database, so the code was pointing to a database that was non existent.

Hopefully this might help some other people out trying to troubleshoot.

user1534664
  • 3,258
  • 8
  • 40
  • 66