A common SQLServer connection error
I have seen many developers struggling with exception "SQLServer 2000 Driver for JDBC Error establishing socket" When connecting to SQLServer 2000 using JDBC.
Here is the stacktrace of the exception thrown when connecting to SQLServer.
Exception in thread "main" java.sql.SQLException: [Microsoft][SQLServer 2000 Driver for JDBC]Error establishing socket.
at com.microsoft.jdbc.base.BaseExceptions.createException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.base.BaseExceptions.getException(Unknown Source)
at com.microsoft.jdbc.sqlserver.tds.TDSConnection.(Unknown Source)
at com.microsoft.jdbc.sqlserver.SQLServerImplConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.getNewImplConnection(Unknown Source)
at com.microsoft.jdbc.base.BaseConnection.open(Unknown Source)
at com.microsoft.jdbc.base.BaseDriver.connect(Unknown Source)
at java.sql.DriverManager.getConnection(DriverManager.java:512)
at java.sql.DriverManager.getConnection(DriverManager.java:193)
This is a very common exception, so here I have explained possible cause and solution to overcome this problem.
This exception indicates that Microsoft SQL Server 2000 Driver for JDBC is not able to connect to SQLServer.
Following are some of the most common reasons of this exception.
You may have specified wrong server name or IP address in database url. Verify that you have network connectivity with the SQLServer which you have used in database url. Ping command can be used to verify basic connectivity to SQLServer
This can be verified by using telnet. Try to connect to SQLServer using following command from command prompt.
telnet IP or Hostname of server 1433
Example : telnet 192.168.1.7 1433 . Make sure that telnet can connect to SQLServer.
To check the enabled protocols for a server, follow these steps:
1. In SQL Server 2000, start the SQL Server
Network Utility (svrnetcn.exe).
2. On the General tab, select the instance of
Microsoft SQL Server on which to load an
installed server network library.
3. Make sure that TCP/IP appears in the Enabled
Protocols list.
4. To find the port number, in the Enabled
Protocols list, click TCP/IP, and then click
Properties. The Properties dialog box
displays the port number.
Make sure that firewall is not preventing you from connecting to SQLServer. If you have any firewall installed turn it off and try to connect again.
For additional information about configuring SQL Server to work behind a firewall Click Here
