aspose file troubles
The moose likes JDBC and the fly likes SQLServerException: TCP/IP connection to the host has failed. The Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » JDBC
Reply Bookmark "SQLServerException: TCP/IP connection to the host has failed. " Watch "SQLServerException: TCP/IP connection to the host has failed. " New topic
Author

SQLServerException: TCP/IP connection to the host has failed.

Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
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
Could be a firewall issue. Can you telnet to that port?

SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Jan Cumps
Bartender

Joined: Dec 20, 2006
Posts: 1628
Could you try sqlserver://127.0.0.1:..... ?

Regards, Jan

tune in turn on phase out
ITIL Foundation
OMG UML Fundamental
Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
Thanks Jan. I tried ip 127.0.0.1, but that did not work either.

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName"><value>com.microsoft.sqlserver.jdbc.SQLServerDriver</value></property>
<property name="url"><value>jdbc:sqlserver://127.0.0.1:1433;databaseName=RX</value></property>
<property name="username"><value>sa</value></property>
<property name="password"><value>admin</value></property>
</bean>
Nina Anderson
Ranch Hand

Joined: Jul 18, 2006
Posts: 148
....also I forgot to add that my FireWall is turned OFF.
George Stoianov
Ranch Hand

Joined: Jan 15, 2006
Posts: 94
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
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
"u and me",
Please check your private messages regarding an important administrative matter.
-Ben

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13390
"John",
Please check your private messages.
-Ben
Ramaswamy Srinivasan
Ranch Hand

Joined: Aug 31, 2004
Posts: 295
Other possible reasons could be,

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
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
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
John, your solution worked fine. Thank you.
Jyothi kana
Greenhorn

Joined: Mar 25, 2010
Posts: 1
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
Thanks John. It works
Jk Harris
Greenhorn

Joined: Jul 13, 2010
Posts: 1
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
Welcome to JavaRanch, Magesh and Jk.
 
aspose file troubles
 
subject: SQLServerException: TCP/IP connection to the host has failed.
 
The most intelligent Java IDE