I just migrated my java web application to a new laptop that has Window Vista on it. However, when I try to start up the Tomcat Server, I'm getting the following error:
com.microsoft.sqlserver.jdbc.SQLServerException: The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDriverError(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(Unknown Source) at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(Unknown Source) at java.sql.DriverManager.getConnection(DriverManager.java:512) at java.sql.DriverManager.getConnection(DriverManager.java:171)
On application start-up, I have data that I need to store in my application variables, so I have to make a database call to extract.
The following are what I'm using: newly installed MS SQL 2005, Hibernate, Spring and Struts.
I have no idea what is causing the error because I did the following: 1. Enabled TCP/IP (under the network's properies -> advance -> WIN tab) 2. Enabled port 1433 under the SQL Server protocol manager. 3. Test connect to the database via MyEclipse IDE (Database Explorer) using path: jdbc:sqlserver://localhost:1433;databaseName=RX. I was able to connect to the database successfully.
What I am doing wrong here? I never used Window's Vista or SQL 2005 before so I don't know what other configuration I need to make. Please Help.
One word of advice on SQL Server is make sure you are running the latest SP as MS is known for breaking its own stuff in the name of "security".
It seems like you are connecting to the loopback interface or localhost, so you may want to have a look at the sql server logs and whether your attempt actually gets registered there as the TCP IP error is indicative of a network problem. Please post the complete error message as well. And one more thing go over your network configuration in SQL Server again and post all properties you see with their values, make sure there is no list or other sort of limit on accepting connections from localhost, also make sure the server is not switching ports for some reason or using named pipes for localhost connections or something strange like that.
My problem is the same as yours. I spent all day crawling from site to site to find the answer but the result is still the same: "The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect". Enable Name pipes, TCP/IP, change Authentication mode, change localhost to 127.0.0.1 or ., add the Instance Name to the url, change the port, enable port and Apps in the firewall... almost everything. Its horrible! But the answer for MY problem is: open SQL Server Configuration Manager -> Protocols for SQL SQLEXPRESS, select Properties of TCP/IP. In the tab IP Addresses, set the TCPPort in section IPAll to 1433. And everthing 's OK. Again, i would like to say: it's the answer to my problem and may be not yours. Thanks!
John wrote:My problem is the same as yours. I spent all day crawling from site to site to find the answer but the result is still the same: "The TCP/IP connection to the host has failed. java.net.ConnectException: Connection refused: connect". Enable Name pipes, TCP/IP, change Authentication mode, change localhost to 127.0.0.1 or ., add the Instance Name to the url, change the port, enable port and Apps in the firewall... almost everything. Its horrible! But the answer for MY problem is: open SQL Server Configuration Manager -> Protocols for SQL SQLEXPRESS, select Properties of TCP/IP. In the tab IP Addresses, set the TCPPort in section IPAll to 1433. And everthing 's OK.
Again, i would like to say: it's the answer to my problem and may be not yours.
Hi john.. Your suggestion really helps me lot thanks...
I don have the same problem. I can not connect to MS SQL SERVER anymore. A couple of days ago everything was fine. But then yesterday I was locked out. I was able to connect via Studio-application but not using JDBC via TCP/IP.
I reinstalled the server and did a lot ot make it work again. I was not able to see the SQL SERVER listening for incomming connection using netstat. Then I found this topic. It helped my to see the server socket to be open on TCP port 1433 again.
But I still can not connect to the DB successfully. The strange behaviour is now:
- if I use a login unknow to the database I get an error saying user ist unknown. The response is quite fast (about 2 seconds)
- if I use a valid login the call to DriverManager.getConnection(...) never returns.
When I stop the server the call to DriverManager.getConnection(...) returns with error: ???
Exception in thread "main" com.microsoft.sqlserver.jdbc.SQLServerException: Connection reset
Any ideas what could be wrong? Unfortunately I can not switch to an other DBS like mysql ...
Steffen Meier wrote:I am using the very actual JDBC driver (sqljdbc4.jar) provided by MS.
I too have this issue. My PC was just upgraded to Windows 7 (from XP). Being a company machine I don't have access to the Firewall to switch it off (and Windows Firewall is configured to popup if its blocking anything but does not popup - so it might be the driver itself).
Strangely enough, if I switch drivers to JTDS (and update the database connection urls) I don't have this problem.
Joined: Oct 31, 2011
I now know why this occurred. I had the latest JDK 6.0 update (29). I uninstalled this and installed update 27. Now the connection to SQL Server works as opposed to just "stopping".
New to the forum... I've run into a situation similar to this. My colleague is running NetBeans 7.1, as am I. JDK 1.7_01. He is on XP, I am on Windows 7. He is able to connect to SQL Server fine using the JDBC driver (sqljdbc4.jar). I am getting the described TCT/IP connection error. We double-checked we are using the same JDBC driver. Tried the same thing on a laptop running Windows 7, NB 7.1, JDK 1.7_01. Connection works. Tried the same thing on another Windows 7 box, NB 7.1, JDK 1.7_01. Same TCP/IP connection error.
Tried NB 6.7.1 running JDK 1.6_23. Unable to connect, just hangs there. Any ideas? I'm going to try on a different Windows 7 box with a fresh install of the OS, NB, etc.
Oh, I forgot to add... I am able to connect via the ODBC tool using the same credentials. Thanks.
I was able to finally determine my root cause to this... it had to do with the proxy settings in the NB IDE. I need to use a proxy, so I added the SQL Server host name to the 'No Proxy Hosts' list, and it now works.
Funny how sometimes when you find the solution, it becomes a 'duh' moment... should have looked at this long ago! Oh well, I learned a lot in the process!