This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Journey To Enterprise Agility and have Daryl Kulak & Hong Li on-line!
See this thread for details.
Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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

 
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 21422
94
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could be a firewall issue. Can you telnet to that port?
 
Bartender
Posts: 2633
17
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you try sqlserver://127.0.0.1:..... ?

Regards, Jan
 
Nina Anderson
Ranch Hand
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 148
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
....also I forgot to add that my FireWall is turned OFF.
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 295
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the same problem and I used the solution provided by John and it worked.

Thank you John.
 
Ranch Hand
Posts: 38
Java MyEclipse IDE Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John, your solution worked fine. Thank you.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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...
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John. It works
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2633
17
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch, Magesh and Jk.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
John, i followed your instructions but i still get the same error message. what should i do?
 
Tan Jee Shiuan
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
solved. 4get to restart it that's y still got the same error message
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks from Argentina John! You help me after hours of search. I only create an account to say this! Regards.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1352)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.terminate(SQLServerConnection.java:1339)
at com.microsoft.sqlserver.jdbc.TDSChannel.read(IOBuffer.java:1654)
at com.microsoft.sqlserver.jdbc.TDSReader.readPacket(IOBuffer.java:3694)
at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:5026)
at com.microsoft.sqlserver.jdbc.TDSCommand.startResponse(IOBuffer.java:4978)

Any ideas what could be wrong? Unfortunately I can not switch to an other DBS like mysql ...

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which version of JDBC driver you are using? You may want to upgrade it, if it is not a recent one.
 
Steffen Meier
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using the very actual JDBC driver (sqljdbc4.jar) provided by MS.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Dean McNabb
Greenhorn
Posts: 2
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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".
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dean McNabb wrote: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".



Thanks a lot to Dean. Downgraded to JDK 6.0 update (27) solved my problem.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dean McNabb wrote: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".


Thank you very much Dean! I did the same and solved my problem.
Vito
 
Greenhorn
Posts: 2
Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alan Douglas
Greenhorn
Posts: 2
Netbeans IDE
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im also facing the connection refused error, please help me.

thanks in advance
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks John. I was also struggling from past 2-3 days regarding the sql server login issue and your instruction helped me resolved the issue. Thanks very much again.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!