Six Possible solutions for JDBC – SQL Server Connection problem

Add a comment March 31st, 2008

Here in this post I am writing about some possible solutions of JDBC – MS SQL server connection problem. During my work I had faced this problem and tried a little hard to findout the solution. In our project when we tried to connect to MSSQL Server, through its default port 1433 it thrown an exception as follows. Hope this will be helpful to you.

com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed.

java.net.ConnectException: Connection refused: connect

If you created the database and you are sure about your connection string then please check the following points.

  1. First Check the port which we are given is free or not. If any other connection is using this then please specify other port.
  2. Check the TCP/IP configuration in “MSSQL surface area configuration”. And if its disabled then make it enable.
  3. Check the Windows Firewall. It may obstruct the port accessing. So please disable it or allow this port accessing through the firewall using windows firewall configuration.
  4. Check if there is any antivirus software is running and it comes in between or not.
  5. Check the Dynamic port allocation of SQL Server is set or not. If it sets to ZERO or any other port then make it ‘Blank’. [making Blank is important] Give the static port number we want to the port number place. These configurations we can do in “SQL Server Configuration manager”. Give IPALL = 1433 also.  This information will set in the following part of the windows registry HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Microsoft SQL Server> MSSQL.1 > MSSQLServer > SuperSocketNetLib > Tcp> IP1/IP2/IPALL. If it’s not changing there we can manually change it.
  6. Then also its not working then please check the Windows Registry where we sets the “SQL Instance’s port number”. If it is different then please set that to our port number. It’s in HKEY_LOCAL_MACHINE > SOFTWARE > Microsoft > Microsoft SQL Server > [Instance name] > MSSQLServer > SuperSocketNetLib > Tcp and change String value TcpPort = 1433.

Are are you reached here? Thanks for reading my full post :) becouse if u are a person who is facing this problem then I am sure you will not reach here, before itself it should solve :) And then also you are here then please check your connection string properly. I am giving an example here.

jdbc.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
jdbc.url=jdbc:sqlserver://servername:1433;DatabaseName=DBName;SelectMethod=cursor

Technorati Tags: ,,
Book Mark it-> del.icio.us | Reddit | Slashdot | Digg | Facebook | Technorati | Google | StumbleUpon | Window Live | Tailrank | Furl | Netscape | Yahoo | BlinkList

Popularity: 22% [?]

Bookmark this on BuzzURLBookmark this on BuzzURL Post to TwitterTweets for this web page Bookmark this on FC2 Bookmark newsing it! Choix it! Add to Google Bookmark Bookmark this on Delicious Digg This

No related posts.

Related posts brought to you by Yet Another Related Posts Plugin.

  1. January 2nd, 2009 at 06:21 | #1
    phil

    Thanks man. You saved the day with this post.
    I was pulling my hair out and so did some googeling.
    One of the pages that came up was this post.
    Steps 5 & 6 where what solved the problem.

    Thanks heaps :-)

  2. January 2nd, 2009 at 10:59 | #2

    Thanks for your good words Phil. :)

  3. January 17th, 2009 at 12:18 | #3

    Respected Sir,

    You are great what a point you just tell us i think most of the problem occur due to no 5 point that u cover.

    Again Thanks

    Truly Regards,

    Tariq

  4. January 19th, 2009 at 11:24 | #4

    Thanks Tariq. You know I wasted my 2 days because of this problem. :) So I thought of putting this in my blog hoping that you people can save your valuable hours… honestly :)

  5. January 28th, 2009 at 15:47 | #5
    raji

    thank you very much for your valuable information

  6. March 26th, 2009 at 11:49 | #6
    AMANDEEP GOYAL

    HI THERE

    I AM FACING A PROBLEM WHILE CONNECTING THROUGH ECLIPSE.
    EVERYTIME I EXECUTE MY CODE FOR CONNECTION, I AM GETTING ERROR: From Base Daocom.microsoft.sqlserver.jdbc.SQLServerException: Login failed for user ‘amandeep’. The user is not associated with a trusted SQL Server connection.
    java.lang.NullPointerException

    COULD YOU HELP IN THIS ISSUE

    THANX IN ADVANCE….

  7. March 26th, 2009 at 11:51 | #7
    AMANDEEP GOYAL

    MY VERSION FOR ECLIPSE IS 3.4 AND I AM USING SQL SERVER 2005..

  8. April 4th, 2009 at 17:36 | #8
    Chose

    Hi Lijin, thank you very much for this article! Step 5 solved my problem!

  9. April 11th, 2009 at 17:18 | #9
    Cornelis, Theo

    Thanks very much! You solved my problem in one minute! Step 5 was the solution. Very good article!

  10. November 20th, 2009 at 00:27 | #10
    Ananda

    Thank you very much.
    You solved the problem where Microsoft failed.

  11. November 21st, 2009 at 03:13 | #11
    Prajakta

    Hey Thanks so much. Point 5 solved the problem for me too ! Thanks !

  1. No trackbacks yet.
Comments feed