views:

78

answers:

2

I am trying to connect to MS SQL Server 2005 from java, I am getting the following error, can anyone help me ?

private static final String DRIVER_CLASS = "com.microsoft.jdbc.sqlserver.SQLServerDriver"; 
Class.forName(DRIVER_CLASS); 
DriverManager.getConnection("jdbc:sqlserver://localhost:1433","sa","root");

I added the following 5 jar files :

  • msbase
  • mssqlserver
  • msutil
  • sqljdbc
  • sqljdbc4

The exception is :

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.<init>(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(Unknown Source)
 at java.sql.DriverManager.getConnection(Unknown Source)
A: 

Is you firewall on? If so, maybe you will need to make an exception for port 1433

Lombo
no i dont have any firewall
Thirst for Excellence
check http://support.microsoft.com/kb/313178
Lombo
This thread also has some possible answers http://forums.sun.com/thread.jspa?threadID=419214
Lombo
A: 

Please check what protocols are enabled on the server. Go to Start/Programs/Microsoft |SQL Server 2005/Configuration Tools/SQL Server Configuration Manager. Check if tcp is enabled under SQL Server 2005 Network Configuration/Protocols for MSSQLSERVER.

Please check if you don't have named instance - SQL Server Express edition by default creates a named instance for example.

And the third - check if SQL Server has mixed mode authentication - if not it will not allow you to connect using SQL login and password. BTW it is a bad idea to use sa account to develop applications.

Piotr Rodak
@Piotr Rodakam :getting error like this while enabling TCP/IP Access denied [0x80041003]
Thirst for Excellence
Can u tell me what exact URL To connect to MS SQL Server2005 ?
Thirst for Excellence
Are you sysadmin on the server box?
Piotr Rodak