If you are receiving following error:
TITLE: Connect to Server
——————————
Cannot connect to Database Server.
——————————
ADDITIONAL INFORMATION:
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: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 1326)
I suggest that you read previous article first as that describes how to fix the problem and has worked for many cases.
SQL SERVER – Fix : Error : 40 – could not open a connection to SQL server
Now if SQL Server can be connected perfectly from local system but can not be connected from remote system, in that case firewall of the server where SQL Server is installed can be issue.

Follow instructions of this article to fix the issue.
Go to control panel >> Firewall Settings >> Add SQL Server’s Port to Exception List.



Now try to connect to SQL Server again. It will allow you to connect to server successfully.
Reference : Pinal Dave (http://blog.SQLAuthority.com)




Hello,
Just to add 2 cents to your notes,
I came across same problem last week, and I came to know that we have to do the following things in order to solve the above issue,
1. Disable windows firewall, or make an exception and add port number for SQL, this works well if you have only one instance of SQL Server, if you have more than one SQL Server instance then I guess you have to enable all other ports used by SQL Server.
2. In “Client Network Utility” tool of SQL Server add the server name of ip address of the server you are trying to register in the Alias section and most important choose which type of protocol you want to choose, either named pipes or TCP/IP
3. If you are using 2005, then use SAC to enable, allow remote connections to server and to use both TCP/IP and named pipes to connect.
Please correct me if I am wrong.
Thanks,
Imran.
There are couple of to troubleshoot this problem. The one you should use depends on how your databse server was configured.
For example, if you configure the database engine to use dynamic port allocation, make sure that sql browser is runnning.
SQL browser provides the connection information about the database engine to the the client.
If the sql browser is not running and you have restarted sql server and port 1433 is being used by other applications,
database engine will be allocated a different port number. Imagine that the client has been configured to use port 1433
to connect and the database engine is using a different port number. The client wont be get the connections properties to the database engine from sql browser
because sql browser is not running.
To avoid this type of problems, when the database engine has been configured to use dynamic ports, make sure that your sql browser
is always running.
Sorry–
There are couple of ways to troubleshoot this problem. The one you should use depends on how your databse server was configured and some other factors as well.
For example, if you configure the database engine to use dynamic port allocation, make sure that sql browser is runnning.
SQL browser provides the connection information about the database engine to the the client.
If the sql browser is not running and you have restarted sql server and port 1433 is being used by other applications,
database engine will be allocated a different port number. Imagine that the client has been configured to use port 1433
to connect and the database engine is using a different port number. The client wont be get the connections properties to the database engine from sql browser
because sql browser is not running.
To avoid this type of problems, when the database engine has been configured to use dynamic ports, make sure that your sql browser
is always running.
I swear, I have absolutely exhausted every concievable solution to this problem, and I’m still stuck.
I’m getting this error in CRM 4.0 when embedding an ASP page with a gridview of information from a stored procedure on my database.
I’m pretty sure it’s Kerberos related, because the page connects fine on my development workstation, but fails on the CRM web server (where there’s a double-hop between my credentials and the SQL server) It’s been broken for weeks now. Here is a (partial) list of the fixes that have NOT worked:
Surface Area configuration: Both Named Pipes and TCP/IP enabled.
SQL Server Browser is running
Added the server name, and the server\instance into my HOSTS file on the server.
Changed my connection string to the IP address, just the hostname, and the hostname\instance name
Added SPNs for every possible permutation of: hostname, host\instance and IP address.
Confirmed that both the NT AUTHORITY\NETWORK SERVICE and HOSTNAME$ accounts have connect rights to the database.
The final weirdness: I wrote another page and put it into another web application on the same web server. It DOESN’T have the error, but it doesn’t work either. The gridview just comes through as an empty tag. Other ASP controls, like labels and buttons, work fine.
At this point, I will give either pinky to get this working.
Forgot: the windows firewall is disabled, and besides, the app works when running in the ASP development server of VS 2005 n my workstation, and of course, all of CRM works (although it mostly uses web services).
I’m getting this same error message ONLY when I specify the IP address as the server name. Everybody else in the office can hit the SQL Server — using the IP address — on my partner’s PC except me! And I can connect if I use the machine name instead of the IP address.
This just started this week, after I installed SQL Server 2008 on MY machine — my partner’s box, the one I’m trying to connect to, is still 2005. It worked fine with EITHER machine name or IP address before that.
It’s not a firewall issue, since everybody else can connect to his server using machine name _OR_ IP address. I can only connect using machine name.
It’s not a protocols issue on his server, because — again — everybody else can connect to him except me. And I ONLY get that error message if I specify the IP address instead of the machine name.
And yes, the IP address is correct. :)
Anyone have a clue?
provider: Named Pipes Provider, error: 40 – Could not open a I was getting this error:
connection to SQL Server) (Microsoft SQL Server, Error: 1326)
I changed the protocol from Named Pipe to TCP /IP and it worked. Thanks.
I was getting this error:
provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 1326)
I changed the protocol from Named Pipe to TCP /IP and it worked. Thanks.
Thanks for the tip about the firewall Dave. I was struggling with this.
Dear sir, i have read your threads for following error :
“An error has occured whil establishing a connection to the server. When connecting to SQL Server 2005, this failure may be casued by the fact that under the default settings dose not allow remote connection.(Provider : Named Pipes Provider, error:40-Could not open a connection to SQL Server)(Microsoft SQL Server Error : 5)”
so please send me possible solutions which i can try.
regards,
ritesh
Dear sir,
i agreed with Ritesh… i m facing same problem, so please send me solutions.
i have read your threads for following error :
“An error has occured whil establishing a connection to the server. When connecting to SQL Server 2005, this failure may be casued by the fact that under the default settings dose not allow remote connection.(Provider : Named Pipes Provider, error:40-Could not open a connection to SQL Server)(Microsoft SQL Server Error : 5)”
so please send me possible solutions which i can try.
regards,
yatin
[...] : If above solution does not help refer the follow up post SQL SERVER – Fix : Error : 1326 Cannot connect to Database Server Error: 40 – Could not open a conne… where additional issues with FIREWALL is explained with images. Reference : Pinal Dave [...]
[...] SQL SERVER – Fix : Error : 1326 Cannot connect to Database Server Error: 40 – Could not open a conne… [...]
[...] find your solution here SQL SERVER – Fix : Error : 40 – could not open a connection to SQL server SQL SERVER – Fix : Error : 1326 Cannot connect to Database Server Error: 40 – Could not open a conne… [...]
I had a similar problem. What I did were change the port address, disable firewall and configure the Network.
Thanks this post help me to solve the problem.
I’ve a named instance (say, INST1) with the port changed to 1432
Under “Connection to server”
SERVERNAME,1432 ==> Every client works fine
SERVERNAME\INST1 ==> Some machines cannot make connection with this server name (seems cannot resolve the port no.)
It makes me confuse since not all clients cannot make connection with SERVERNAME\INST1
Hello Sir,
I am facing one small problem in one of my dummy SQL setup that I have prepared for TPC-E benchmark.This is just to have testrun before I go ahead with the actual test with real setup.
Just to give a brief : I have different Database server and Client server .Setup is prepared as mentioned below.Now I am trying to use SNAC tool to establish connectivity between the two .But MDAC is working fine.My trouble epicenter is Server-Client Connectivity using SNAC tool.
I have a separate Server installed with SQL Server 2008 , service also started , created one database through TPC-E scripts, installed SNAC tool.
I hv separate Client machine on same network ( both can reach each other over TCP/IP) , installed SNAC tool.
Now I am getting an error: “Message:[Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified ” , whenever I start some TPC-E scripts on Client machine to start work on Database server.
In the process I tried some DSN configuration as described here http://www.mssqltips.com/tip.asp?tip=1471 . I tried to define it on both Server and Client .But this is not working.
Have also tried with Aliases creation .Referring to http://www.mssqltips.com/tip.asp?tip=1620.
What settings to be made on both Server side and Client side to overcome this issue. Any extra components I need install on Client side or Server side.
One more thing I hv observed is that SNAC version on both Client and server are different , can this be a problem. Is it required to be same.
Any relevant inputs on this will be helpful.
At the end I should tell you that I am pretty new to this SQL server domain , so my level of struggle has been quite at a higher scale all through the project run.Hope this will over soon.
Thanks & Regards,
Sudipt.
After all the steps mentioined above, you might still not be able to connect for SQL2005 Express.
One of the trick for SQL2005 express is that when you connect the server, you can’t just type the server name but have to type “servername\EXPRESS” instead. This applies to both SQL Server Management Studio and the code.
Dear sir,
I got this error while configuring transactional replication between two different SQL Server 2008.
I have two SQL 2008 Servers, connected via internet such as A and B.
I configure Publisher on Server A and try to add the subscriber the server B, but unable to connect the server B
error as “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) (.Net SqlClient Data Provider)”
When I use the Management studio of Server A to connect the server B the connectivity is done successfully,
But while adding subscriber it does not work..
Please help me in this regards.
Hi,
I’ve installed SQL Server 2005 and ‘Query Express’ to access it on the same PC. When I’m getting this connection failure error 40 message & I’ve applied all the advise given on above but nothing seems working. I feel exhausted now. Please adivse.
Many Thanks.
Hi All
I have a SQL Server 2000 running on Win2k3.
I am trying connecting to SQL locally on the Enterprise Manager on the machine but
I get this error: “A Connection could not be established to local
Reason: Encryption not supported in sql server
Connectionopne (prelogin(handshake)).”
The odd thing is that I can connect to that SQL Server from other
remote machines through Enterprise Manager, I just can’t connect
locally. All help is appreciated.
Thanks
Hi All,
I was able to solve it. We just need to uncheck the Encryption support in Client Network Utility. But now I am not able to connect to other sql server DB on other machine, but still I can’t connect to this DB from other machinet. I am getting error
“Msg 17, Level 16, State 1
[ODBC SQL Server Driver][DBNETLIB]Sql Server does not exist of access denied
Please help me to troubleshoot this.
Thanks
Mithalesh
Hi,
There can be multiple reason why this error is coming up.
http://blog.sqlauthority.com/2007/04/23/sql-server-fix-error-40-could-not-open-a-connection-to-sql-server/
http://blog.sqlauthority.com/2008/08/24/sql-server-fix-error-40-could-not-open-a-connection-to-sql-server-fix-connection-problems-of-sql-server/
http://blog.sqlauthority.com/2008/08/09/sql-server-fix-error-1326-cannot-connect-to-database-server-error-40-could-not-open-a-connection-to-sql-server/
http://blog.sqlauthority.com/2008/08/30/sql-server-fix-error-could-not-connect-to-sql-server-tdssniclient-initialization-failed-with-error-0×7e-status-code-0×60/
http://blog.sqlauthority.com/2007/06/10/sql-server-fix-error-an-error-has-occurred-while-establishing-a-connect-to-the-server-solution-with-images/
Best Regards,
Pinal
My Client is on Win Server 2003 and Server on Wix XP 3. I thought that might be helpful to you in helping me.
hii,
I try to connect to my database sql server 2005 from a jcreator app usind odbc… The main problem is that I can not configure the odbc data sources to connects using neither named pipes nor tcp/ip please help
I am getting this kind of error. can you please help me solve this problem . when i was installing SQl sever at that time i didnt give any login name and password . so i dont know what to give in login name and password. and also have problem with connecting SQL sever
please help me out
TITLE: Connect to Server
——————————
Cannot connect to 76.194.236.194 .
——————————
ADDITIONAL INFORMATION:
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) (Microsoft SQL Server, Error: 3)
——————————
i also tried solution ( add port ) but still give me same error.
Hi,
(.net 2005 C# Windows Application)
My Connection String is :
string ConnString = “Data Source =//./pipe/MSSQL$SQLEXPRESS/sql/query;Initial Catalog=ErollNewDotNet;uid=sa;pwd=sa;”;
I got error like this at this point :
SqlConnection SqlCnObj = new SqlConnection(ConnString);
–> SqlCnObj.Open();
The error is:
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 have checked :
–Sql server service is running,
–Named Pipe and TCP/IP both are enabled;
–Firewall is Off and Remote connection is also enabled .
And the most socking thing is same connection string is running successfully in my other web application project.
Y this Error ? Please Help me asap.
Thanks in Advance.
Latu.
Hi!
I’ve had a problem and solved it!
On remote machine in “SERVER NAME”, I’ve entered a name in format “%computername%\SQLEXPRESS” and everything worked just fine.
I have problem in SQL2000 Server. Here is what i got an error while connecting remotely.
—————————
SQL Query Analyzer
—————————
Unable to connect to server 10.0.0.153\sql2k:
Server: Msg 17, Level 16, State 1
[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.
—————————
OK
—————————
Instance name is correct i could able to connect locally. But couldn’t able to connect remotely.
Firewall is off in my server and even i checked Default port of TCP\IP protocol properties. Earlier it was 0 after that i configured with 1433. But problem is Remain same.
Hi all, i have a question.
First i don’t have any experience with sql.
Now.
I want to make a private server for a game named Kal online.
After much researching i found a guide that said to install SQL.
Now i have downloaded SQL 2000 and i installed it on vista.
Many people say it can’t but he installed it so i want to give it a try.
After the installation i open the server but i get this massage:
Acces denied
and then An error 5 occuredwhile peformingthis service operation on the MSSQL service.
I have searched and searched but i can’t seem to find a solution!!
I hav tried all the above but it doesn’t help.
I really hope someone can help me with this problem!!
greetings nick
need to enable netbios then it worked.
And where can i do that?
@mac
I found it, did it but i still have the problem.
Maybe i did something wrong with installation??
hello
it my problem in the sql server2005 is connected ..
so then and sever name is not show …
can you tell me how is connect the sql server 2005 …
pls tell
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: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server) (Microsoft SQL Server, Error:2)
pls tell me
i dont understand i waiting your reply…
1. Allow remote connections… CHECK
2. Firewall open… CHECK
3. Instance is on port 1433… CHECK
4. SQL Browser is not running… CHECK
I would get this error when using the IP address as the Data Source. Also when using IP,1433. However, when I switched to a DNS name that resolves to the same IP address, the error went away. Go figure!
@Lex3001
3. Instance is on port 1433… CHECK
You can have any port number for SQL Server. By Default SQL Server will be using port 1433, it does not mean that you/sql server cannot use any other port. This should not be an issue.
I would add one more check to your check list, as
Step 0. First, Check if SQL Server Service for that particular Instance is running or not— CHECK
When SQL Server to which you are connecting is a Default Instance then you can use IP Address as your data source
SQL Server : Default instance
IP Address to connect : ip address of host machine.
Ex :
SQL Server : Default instance
ip address of host machine : 192.168.1.100
Then you will use the same ip address.
When connecting to Named instance of SQL Server, then you will use
SQL Server : ComputerName\InstanceName
IP Address to connect : ip address of host machine\InstanceName
Ex:
SQL Server : IMRAN\PROD
Ip Address of host machine : 192.168.1.100
IP Address to connect : 192.168.1.100\PROD
One more important reason why this could fail,
Check your Port No: Its need not be always 1433,
Use this script to find out port no of sql server instance.
http://www.sqlservercentral.com/scripts/Miscellaneous/67422/
~ IM.
Hello Sir, i have one asp.net applcation which is running on my LAN …..
Some time i got this kind of error when i start my application “The connection was not closed. The connection’s current state is open.”
and
i also got this kind of error ” Timeout expired”
plz try to sloved my error …………
Thanks a lot. Start SQL Browser resolved the issue.
Verrry helpful.
Our admin spent a day to try to resolve this issue.
I got this help, teach him and got the credit as Smart(test)… kidding. Anyway thanks a lot for the site!
Really helpful!!!
mssqlserver should started fist, it will solve the problem