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
0 Responses to “Six Possible solutions for JDBC - SQL Server Connection problem”