Six Possible solutions for JDBC – SQL Server Connection problem
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.
- First Check the port which we are given is free or not. If any other connection is using this then please specify other port.
- Check the TCP/IP configuration in “MSSQL surface area configuration”. And if its disabled then make it enable.
- 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.
- Check if there is any antivirus software is running and it comes in between or not.
- 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.
- 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
Popularity: 22% [?]
No related posts.
Related posts brought to you by Yet Another Related Posts Plugin.
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
Thanks for your good words Phil.
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
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
thank you very much for your valuable information
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….
MY VERSION FOR ECLIPSE IS 3.4 AND I AM USING SQL SERVER 2005..
Hi Lijin, thank you very much for this article! Step 5 solved my problem!
Thanks very much! You solved my problem in one minute! Step 5 was the solution. Very good article!
Thank you very much.
You solved the problem where Microsoft failed.
Hey Thanks so much. Point 5 solved the problem for me too ! Thanks !