0

I've tryed to create a connection with a Microsoft SQl Server 2008 database through JDBC on Eclipse SDK. I've dowloaded JDBC driver from microsoft and I've installed it, then I've added at my System environment variables CLASSPATH the path of sqljdbc4.jar file. After icluding in the Eclipse project the jar file I've tryed to create the connection using:

String connectionUrl = "jdbc:sqlserver://localhost;integratedSecurity=true";
Connection con = DriverManager.getConnection(connectionUrl);

but it doesn't works, and launch me this exception:

com.microsoft.sqlserver.jdbc.SQLServerException: TCP/IP connection at host localhost, port 1433 failed. Error: "Connection refused: connect. Verify connection properties and make sure an instance of SQL Server is running on the host and is accepting TCP/IP connections at the port. Be sure no firewall blocks connections at the port.

I'm working on a JRE 1.6 so a sqljdbc4 should work, and I've created a working ODBC, so the server is responding, and the error should be in java command or JDBC installation.

Can anyone help me?

marc_s
760k186 gold badges1.4k silver badges1.5k bronze badges
asked Jul 28, 2011 at 10:40
1
  • Have you tested telnet on port 1433? Or have you checked the database is up at all? Go to MS SQL Server Manager and check. Commented Jul 28, 2011 at 11:31

2 Answers 2

2

At the risk of stating the obvious, this looks to me as if TCP connections haven't been enabled on SQL Server. You have to manually enable them, they don't come enabled by default.

There's an article on MSDN here which explains how to enable TCP protocols for SQL 2005/2008.

answered Jul 28, 2011 at 10:43
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you very much, TCP/IP was not enabled but I didn't know how to set it, very useful :)
No probs, I've been bitten by this exact problem a few times! :)
0

Following are the quick trouble shooters:

  • Try to connect to your server using external front end.

  • Check if your firewall blocks the connection to the port

  • Check to see if server is really up.

A Suggestion :

If you are using eclipse , you don't need to add the jar into CLASSPATH variable , you can just add it in library of your project to make it available at runtime

answered Jul 28, 2011 at 10:45

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.