Why I am not able to connect to remote SQL Server

2019-08-09 05:45发布

问题:

Why I am not able to connect to remote server from asp.net website whereas it is connecting from SSMS

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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

I tried all the possible solution suggested in this link

I checked Followings as given in the above article, they are enabled/running

  1. SQL Server is up and running.
  2. TCP/IP enabled in SSCM
  3. Opened port in Windows Firewall
  4. Remote Connection enabled
  5. SQL Server Browser Service running

I searched for sqlbrowser.exe but it is not found in the given directory.

Finally I switched off Windows Firewall but still it is not working.

UPDATE: we are connecting to sql server using a custom user created on sql server (not sa ) I have user account credential to Remote connect to server. I tried to change LogOn to my credentials (administrator) . in Windows Services SQL Server (MSSQlServer) and SQL Server Agent (MSSQL Server) services.

回答1:

Double check your connection string - are you connecting to a hostname that needs to be added to your Hosts file? For example "dev-sql1" but without a matching entry in dns or hosts file.



回答2:

If you have created a custom user, can you check if logins are disabled for the user? In SSMS, goto Security, right click user, Properties -> Status, Login - Enabled.

Hope this should fix it.



回答3:

Three possibilities and they are not mutually exclusive.

  1. Most hosting providers disable remote connections to SQL servers. Check with RackSpace if blocking port 1433

  2. The SQL Server needs to be reconfigured to accept remote connections. See http://support.microsoft.com/kb/914277

  3. You have to use a different connection string. See http://www.connectionstrings.com/sql-server and look for Connect via an IP address



回答4:

I got the same issue but with mysql server. Rack space had two mysql server address. One for connecting from outside their local network and one for connecting from inside the network. you will have to use the address that is required to connect from inside the network.