Why I am not able to connect to remote SQL Server from asp.net website whereas it is connecting from SQL Server Management Studio - asp.net

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
SQL Server is up and running.
TCP/IP enabled in SSCM
Opened port in Windows Firewall
Remote Connection enabled
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.

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.

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.

Three possibilities and they are not mutually exclusive.
Most hosting providers disable remote connections to SQL servers. Check with RackSpace if blocking port 1433
The SQL Server needs to be reconfigured to accept remote connections. See http://support.microsoft.com/kb/914277
You have to use a different connection string. See http://www.connectionstrings.com/sql-server and look for Connect via an IP address

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.

Related

How to access remote sql server located in other place

I have shared published website and the database files to our client.
they have restored the database to their server.
Now they have changed the connection string in web.config with new server name/IP address and a proper user name and password.
My client said that he can login sql server using the same password and username. But when the website is launched through IIS with same (username and password in web.config and same db structure), it gives an error:
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) (.Net SqlClient Data Provider)
For help, click: http://go.microsoft.com/fwlink?ProdName=Microsoft+SQL+Server&EvtSrc=MSSQLServer&EvtID=53&LinkId=20476
Error Number: 53
Severity: 20
State: 0
The ip address of the server starts with 172.
Any help would be highly appreciated.
I would check these things:
I would check the SQL Server Configuration Manager to see if the TCP/IP communication is enabled.
I would check the firewall settings. A firewall could prevent traffic from/to the server.
I would check if another application from the same client can connect to the same server. Then I would check the connection string differences.
If all of the above were playing correctly, then I would check the privileges on the specific SQL Server, on the specific database, for the account I am trying to connect with. Allow everyone to use this database as a first step to check if it is an account-permissions problem.
You could check this connection strings example post.
Hope I helped!

Could not open a connection to SQL Server

I have problems connecting to my database server. The database server is not local, I am connected via its IP address.
It works fine in my development machine. After publishing the website to my server, it can not connect to my database server.
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)
Why can't my publish server connect to the database server, whereas it works fine through the development machine?
I often had that problem. Mostly it's because of two problems.
Open the SQL Server Configuration Manager.
Check if the SQL Server Network Configuration supports TCP/IP, if it's disabled, enable it.
e.g. SqlServer 2005 Network Configuration, Protocols for SQLEXPRESS
Open the SQL Server Management Studio
Click on the Sql Server Properties (right click on the server name and
select properties).
After that, select the page "Security" and switch the check to "SQL Server and Windows Authentication mode".
That's all.
I'll attempt to go two for two on the psychic debugging for today...
I will assume that you are not using integrated security? If so it might explain things as the account on your local machine probably has permissions, but the SYSTEM account that is running on the server does not. Just a shot in the dark though.
It sounds like your server can't make the network connection, rather than a security issue.
Ensure that any firewalls on both the DB and app servers allow traffic on the port (1433).
Ensure you're able to ping or tracert from both machines.
Is it your first time you publish your website on the web server ? if it is , Are you sure you have set your connection string properly ?
You need to create a login ( of curse a password for that too ) and the IP Address of that SQL on the web server .
So you need IP Address of the sql server host , Database Name , UId , Pwd .
I will agree that this sounds like a network issue and not a security issue.
Remote into the web server and ping the DB server by IP address. If this does not work, your server cannot see the DB server via that address (different subnet, incorrect firewall/proxy setup, etc). There may be a proxy address you must use to get to the DB server from the web server, or your web server may also be the gateway and IIS doesn't know to look for the DB server on the LAN. If it does work, the computers may not be talking on the same port, or the firewall may be blocking that port exiting the web server.
I have spent hours trying to connect to SQL server using sqlcmd. I disabled my firewall, checked all ip listed in "Protocols for SQLEXPRESS", edited my hosts file. I tried using different ips and machinename to connect to the server. But none of work worked. After hours of investigation, I found out that I made absolutely stupid blunder making me unable to connect.
I want to remind people that the connection string is not case sensitive. But the option is!!
what i did is I put
sqlcmd -s .\sqlserver
But the correct string is
sqlcmd -S .\sqlserver
so watch out, people

I can't display my pages on ASP.NET

I'm developing a web site with asp.net on localhost, I'm beginner. I wrote a login page and it
works well. However when I click a link, the server can't load the page and gives this error:
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)
Any idea?
This means you either:
provided the wrong login/password for SQL while using SQL authentication
have used Windows authentication for SQL but the user that your web app is running as doesn't have a login
have provided the wrong connection details for the sql instance so it can't be found
don't have remote connections enabled for that SQL server instance
Are you using SQL server? If yes, run a debug and see what is the connection string at run time and whether you can connect to the DB using the connection string.
In case you are not using SQL server, it seems, you have extended the membership provider but not done so for the role provider. The default role provider tries to connect to SQL Server instance.

Asp.net - Microsoft SQL Server outgoing connections

I was wondering if there is a way to see if a server blocks outgoing connections. I am trying to connect to an external database from a client's server.
This is the error I get:
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: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)
Edit:
I forgot to say I only have access to the plesk control panel. That's why I was asking if there is a way with asp.net.
When you say "server", do you mean the asp.net server, or the SQL server? And are both machines on the same network? Is this hosted?
Sql Server:
They can remove the OPENROWSET functionality, so you can't connect to remote servers, regardless
I doubt they are giving you access to linked servers in a hosted env
ASP.Net
You can try to connect to the other server via a regular connection, and see if that works.
Download a tracert component, and use that to try to trace from your server to the remote one.
If it dies somewhere inside your network, then that is your answer (it is blocked)
If it works, the outbound is open. Doesn't mean 1433 is open though.
If it dies after, not blocked, but maybe the remote is blocking icmp echo
Remember to try to tracert to somewhere else that you know works
It will be hard to tell what is killing the connection on 1433, if you can get to the server using other means. Could be the firewall, their fw, etc.
The trusty telnet method:
telnet theserver 1433
If this times out, the server is not listening. If the screen blanks and you can type something, the server is listening and no firewall is blocking the connection.
In Vista and Windows 7, you have to install telnet as a Windows component from Control Panel -> Programs and Features.

Getting a sql connection error when trying to login

I have a login page that works in my local development environment. When I push the site onto the web server, i am getting this error when trying to login from the asp.net login control.
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
I cannot figure out why it does not work on the server. Do I need to add anything or change something in the web.config?
This support article may help. It may also be a firewall issue or an authentication issue on the new setup (but the error message makes that less likely).
For resolving error 26 in sql server you need to do the following steps.
At Server System
1. Under surface area configuration manager-Open up remote connections.
2. Add into firewall 1433 and 1434 port no as n exception.
3. Open port 1433 on router for WAN access.
4. Add client machine ip address as an exception to your antivirus or allow LAN settings in antivirus.
5. Now try to check if both client and server are connected to each other.
for this type "ping IP address of remote system" at run and if reply is obtained then do same for server machine.
If reply is obtained from both machines.
Open Sql server and try to connect to remote machine which allow remote connections using its ip address. U will surely get connected to server machine
See this video
Check to make sure TCP/IP is enabled on the SQL Server. For whatever reason, named pipes and TCP/IP is off by default. Also make sure you are trying to connect to the correct instance (maybe you are using ./SQLEXPRESS locally and on the server SQL is installed on the default instance). Lastly, make sure the database you are trying to connect to exists on the server.

Resources