SQLServerException: TCP/IP connection to the host has failed.
Nina Anderson
Ranch Hand
Joined: Jul 18, 2006
Posts: 148
posted
Hi,
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.
Rob Prime
Bartender
Joined: Oct 27, 2005
Posts: 11146
posted
Could be a firewall issue. Can you telnet to that port?
....also I forgot to add that my FireWall is turned OFF.
George Stoianov
Ranch Hand
Joined: Jan 15, 2006
Posts: 94
posted
Hi Nina,
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.
HTH George
John
Greenhorn
Joined: Apr 23, 2008
Posts: 1
posted
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!
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13390
posted
"u and me", Please check your private messages regarding an important administrative matter. -Ben
1. The chosen port while installing the SQL Server might be already in use.
2. Permissions to the user name which is accessing the database might not have been granted.
3. If it a remote machine, remote settings are not enabled.
Matei Costescu
Greenhorn
Joined: Aug 25, 2008
Posts: 1
posted
I had the same problem and I used the solution provided by John and it worked.
Thank you John.
Rajasekhar Pentakota
Ranch Hand
Joined: Aug 28, 2007
Posts: 31
posted
John ... what ever solution provided you is really worth.. I have tried many ways provided in many blogs.. but couldn't make out.. but your solution has shown all the way.. Its general problem..
Thanks a lot!!!
Thanks
Rajasekhar
Rodney Hirokane
Greenhorn
Joined: Dec 04, 2009
Posts: 3
posted
John, your solution worked fine. Thank you.
Jyothi kana
Greenhorn
Joined: Mar 25, 2010
Posts: 1
posted
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.
Thanks!
Hi john.. Your suggestion really helps me lot thanks...
Magesh Rajni
Greenhorn
Joined: Jul 06, 2010
Posts: 1
posted
Thanks John. It works
Jk Harris
Greenhorn
Joined: Jul 13, 2010
Posts: 1
posted
Thank you John. It worked. I forgot that above certain releases for security purposes that MS distributes software with stuff turned off as the default.
Jan Cumps
Bartender
Joined: Dec 20, 2006
Posts: 1628
posted
Welcome to JavaRanch, Magesh and Jk.
subject: SQLServerException: TCP/IP connection to the host has failed.