Topics from the Microsoft SQL Server Protocols team - Netlibs, TDS, SQL Browser, etc.
We have been seeing and trying to resolve SQL connectivity issue all the time. I guess it would be helpful if we can put some guidance on how to resolve connectivity issues. Here comes a proposal based on my experience.
Basically, when you failed to connect to your SQL Server, the issue could be:
1) Network issue,
2) SQL Server configuration issue.
3) Firewall issue,
4) Client driver issue,
5) Application configuration issue.
6) Authentication and logon issue.
Usually, customers see connectivity issue in their applications, but it would be great if you can follow the steps below to eliminate issues one by one and post a question on SQL Server Data Access forum if needed.
Step 1: Network issue
You might be able to make local connection without a working network, but that's a special case. For remote connection, a stable network is required. The first thing to trouble shoot SQL connectivity issues is to make sure the network we rely on is workable and stable. Please run the following commands:
ping -a <your_target_machine> (use -4 and -6 for IPv4 and IPv6 specifically)
ping -a <Your_remote_IPAddress>
nslookup (type your local and remote machine name and IP address multiple times)
Be careful to see any mismatch on the returned results. If you are not able to ping your target machine, it has high chance that either the network is broken or the target machine is not running. It's possible the target machine is behind a firewall and the firewall blocks the packets sent by ping, though. Windows firewall does not block ping (ECHO) packet by default. The correctness of DNS configuration on the network is vital to SQL connection. Wrong DNS entry could cause of all sorts of connectivity issue later. See this link for example, "Cannot Generate SSPI Context" error message, Poisoned DNS.
Step 2: SQL Server configuration issue
You need to make sure the target SQL Server is running and is listening on appropriate protocols. You can use SQL Server Configuration Manager (SCM) to enable protocols on the server machine. SQL Server supports Shared Memory, Named Pipes, and TCP protocols (and VIA which needs special hardware and is rarely used). For remote connection, NP and/or TCP protocols must be enabled. Once you enabled protocols in SCM, please make sure restart the SQL Server.
You can open errorlog file to see if the server is successfully listening on any of the protocol. The location of errorlog file is usually under:
%ProgramFile%Microsoft SQL Server/MSSQLxx.xxx/MSSQL/Log
If the target SQL instance is a named instance, you also need to make sure SQL Browser is running on the target machine. If you are not able to access the remote SQL Server, please ask your admin to make sure all these happen.
Step 3: Firewall issue
A firewall on the SQL Server machine (or anywhere between client and server) could block SQL connection request. An easy way to isolate if this is a firewall issue is to turn off firewall for a short time if you can. Long term solution is to put exception for SQL Server and SQL Browser.
For NP protocol, please make sure file sharing is in firewall exception list. Both file sharing and NP use SMB protocol underneath.
For TCP protocol, you need put the TCP port on which the SQL Server listens on into exception.
For SQL Browser, please put UDP port 1434 into exception.
Meanwhile, you can put sqlservr.exe and sqlbrowser.exe into exception as well, but this is not recommended. IPSec between machines that we are not trusted could also block some packets. Note that firewall should never be an issue for local connections.
Step 4: Client driver issue
At this stage, you can test your connection using some tools. The tests need to be done on client machine for sure.
telnet <your_target_machine> <TCP_Port>
You should be able to telnet to the SQL server TCP port if TCP is enabled. Otherwise, go back to check steps 1-3. Then, use OSQL, SQLCMD, and SQL Management Studio to test sql connections. If you don't have those tools, please download SQL Express from Microsoft and you can get those tools for free.
OSQL (the one shipped with SQL Server 2000) uses MDAC.
OSQL (the one shipped with SQL Server 2005 & 2008) uses SNAC ODBC.
SQLCMD (shipped with SQL Server 2005 & 2008) uses SNAC OLEDB.
SQL Management Studio (shipped with SQL Server 2005 & 2008) uses SQLClient.
Possilbe command use be:
osql -E -SYour_target_machine\Your_instance for Windows Auth
osql -Uyour_user -SYour_target_machine\Your_instance for SQL Auth
SQLCMD also applies here. In addition, you can use “-Stcp:Your_target_machine, Tcp_port” for TCP, “-Snp:Your_target_machine\Your_instance” for NP, and “-Slpc:Your_target_machine\Your_instance” for Shared Memory. You would know if it fails for all protocols or just some specific procotols.
At this stage, you should not see general error message such as error 26 and error 40 anymore. If you are using NP and you still see error 40 (Named Pipes Provider: Could not open a connection to SQL Server), please try the following steps:
a) Open a file share on your server machine.
b) Run “net view \\your_target_machine” and “net use \\your_target_machine\your_share” (You can try Map Network Drive from Windows Explorer as well)
If you get failure in b), it's very likely you have OS/Network configuration issue, which is not SQL Server specific. Please search on internet to resolve this issue first.
You can try connection using both Windows Authentication and SQL Authentication. If the tests with all tools failed, there is a good chance that steps 1-3 were not set correctly, unless the failure is logon-related then you can look at step 6.
If you succeeds with some of the tools, but fails with other tools, it's probably a driver issue. You can post a question on our forum and give us the details.
You can also use “\windows\system32\odbcad32.exe” (which ships with Windows) to test connection by adding new DSN for various drivers, but that's for ODBC only.
Step 5: Application issue
If you succeed with steps 1-4 but still see failure in your application, it's likely a configuration issue in your application. Think about couple of possible issues here.
a) Is your application running under the same account with the account you did tests in step 4? If not, you might want to try testing in step 4 under that account or change to a workable service account for your application if possible.
b) Which SQL driver does your app use?
c) What's your connection string? Is the connection string compatible to your driver? Please check http://www.connectionstrings.com/ for reference.
Step 6: Authentication and logon issue
This is probably the most difficult part for sql connectivity issues. It's often related to the configuration on your network, your OS and your SQL Server database. There is no simple solution for this, and we have to solve it case by case. There are already several blogs in sql_protocols talking about some special cases and you can check them see if any of them applies to your case. Apart from that, things to keep in mind:
a) If you use SQL auth, mixed authentication must be enabled. Check this page for reference http://msdn.microsoft.com/en-us/library/ms188670.aspx
b) Make sure your login account has access permission on the database you used during login ("Initial Catalog" in OLEDB).
c) Check the eventlog on your system see if there is more information
At last, please post question on our forum. More people could help you over there. When you post question, you can refer to this link and indicate you see failure at which step. The most important things for us to troubleshoot are a) exact error message and b) connection string.
Xinwei Hong, SQL Server ProtocolsDisclaimer: This posting is provided "AS IS" with no warranties, and confers no rights
i right click on data connection & select create new sql connection & type my server name & type something my database name & click on ok then it give error 40
With all the data moving into the "cloud" I was wondering if someone could point me to some good resources reguarding trying/catching specific SQL server events... such as trapping: (TSQL 2008r2 server) "Msg 6005, Level 14, State 2, Line 1 SHUTDOWN is in progress." Plus any ideas for handling basic connectivity issues programatically.
Right now my focus is on web development using C# (ASP4.NET/MVC) and MS Access 2010 dev (using VBA 7.0).
I am having problem running the sqlcmd command in my linux box with an error "Unable to load SQLCMD resource file(s)". After investigating this I realized that the driver and sqlcmd are looking for the resource files at a specific path /opt/microsoft/msodbcsql location. In my environment this is not possible:
1) I am not an admin and can not access to that directory
2) We use enterprise file system so individual machine installation directory is not allowed.
Is it possible to have the driver look at some other location for resource files?
Please let me know, since this is stopping me from going forward.
Hi - I set up a test and production instance SQL Server 2008 R2 Express.
The test I installed on the default c:\ drive and works fine. The production I installed the data on the e:\ drive and I can't get to it. However the application works fine from the production server. Any Ideas?
I am not able to connect to SQL 2005 DB in windows authentication,plz help me out...i'm gtng an error as follows....
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: 25 - Connection string is not valid) (Microsoft SQL Server, Error: 87)
For help, click: ht
Changing name on the server after installing MSSQL-server was my problem. Uninstalling MSSQL and reinstalling it solved the problem. 12h testing there for you guys. :-)
I have an ASP.NET/IIS 6 based application that runs on a SQL Server 2000 database on Windows 2003. We lost the server and we are trying to setup the application from scratch in a new machine. The application fails with error 40 and also error 26 (cannot locate SQL Server connection). The application and the database are on the same host. No local firewall is running. The OSQL utility works correctly. If I install the IIS application in another machine, that application is actually capable to connect to the database (the connection error happens locally only).
The connection string I'm testing in the web.config file is this: <add name="keyconnection" connectionString="Data Source=10.162.6.199; Initial Catalog=EDM2Pruebas; User ID=xxxx; Pwd=xxxxx" />
In the connectionString I have tried the server name, the IP address, the (local) keyword, and all of them fail.
Any ideas of what I might be missing?
TITLE: Connect to Server
Cannot connect to MOHAMED-PC.
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 - No connection could be made because the target machine actively refused it.) (Microsoft SQL Server, Error: 10061)
For help, click: go.microsoft.com/fwlink
Hi, I need urgent help here.
1. Windows 7,
2. SQL Server 2000 setup successfully installed with Sql Server Authentication.
3. Created two users for Sql authentication. Given permission to my tables for both
4. I want to run my application using vb6 on two clients machines A, B.
5. Test connection is OK on both clients A and B
6. Problem is simple, when i login from my A client system, it very easily login to my application main menu when i enter login name and passsword.
7. But when i try to login from B client system, then after getting username and password, it does not show application Main menu hang on and time out expire msg listed later.
8. and when log out from my first A system, and then try to login from B, then it easily go through and show App main menu and vice versa......????
Plz help me soonnnnnnnnnnnn...waiting thanks
Hi I am using mixed mode authentication still we are getting Error: 18456, Severity: 14, State: 58.
Please help on this
We are getting Error: 18456, Severity: 14, State: 58. Mysql server is 2008r2 and it is configured with mixed mode.
Still users are not able to connect sql server, ould you please help on this
Thanks for the article. I was trying hard to follow the instruction on other tutorials. Your's is the only one mentioning the necessity of SQL Server Browser running. :) Saved me further headaches.
SQL Server was not accessible from the requesting machine. how we make the 2 machine communicate
Error: Error locating server/instance specified
It works for some users and don't for few.
1. When the exe is copied to local drive (C:\ or O:\) and launched from local drive, exe is able to connect to MS SQL database and the process works fine.
2. When the network path of exe location is mapped to a drive locally (say P ) and exe is launched from P:\ that doesn’t work (fails connecting to MS SQL database).
3. When the exe is launched from network path it never worked.
Exe is in .net , Connectstring uses SQL auth.