Question

I have a java program that connects to a MS SQL database. The program works perfectly when running through eclipse however I get an error when I run it through AIX:

java.sql.SQLException: Network error IOException: A remote host refused an attempted connect operation.

I can successfully ping the server but am not able to telnet into the server. I am also not able to telnet from my windows desktop.

I am using jtds to connect:

String connectionString = "jdbc:jtds:sqlserver://"+dropez_ip_address+"/"+dropez_db_name;
ResultSet rs = null;
Statement stmt = null;

try{

    Class.forName("net.sourceforge.jtds.jdbc.Driver");
    Connection conn = DriverManager.getConnection(connectionString, dropez_db_username, dropez_db_password);

    stmt = conn.createStatement();
}catch(Exception e){}

Here is some documentation from jTDS regarding the issue, but I am still not able to resolve the issue.

Why do I get java.sql.SQLException: "Network error IOException: Connection refused: connect" when trying to get a connection?

The "Connection refused" exception is thrown by jTDS when it is unable to connect to the server. There may be a number of reasons why this could happen:

    - The server name is misspelled or the port number is incorrect.
    - SQL Server is not configured to use TCP/IP. Either enable TCP/IP from SQL Server's Network Utility app or have jTDS connect via named pipes (see the URL format for information on how to do this).
    - There is a firewall blocking port 1433 on the server.

To check whether TCP/IP is enabled and the port is not blocked you can use "telnet 1433". Until telnet doesn't connect, jTDS won't either. If you can't figure out why, ask your network administrator for help.
Was it helpful?

Solution

Your SQL Server database probably doesn't have the TCP/IP protocol enabled, to enable it:

  1. From the Microsoft SQL Server 2005 -> Configuration Tools, open the 'Microsoft SQL Server Configuration Manager'.

  2. Expand ‘SQL Server 2005 Network Configuration’, and then click ‘Protocols for ’.

  3. Right-click ‘TCP/IP’ and then click ‘Enable’. The icon for the protocol will change to show that the protocol is enabled.

For SQL Server 2008:

SQL Server 2008 Network Configuration

OTHER TIPS

If you can't telnet on port 1433, you are blocked by a firewall somewhere in the middle between your machine and the server. That's not a java related problem.

May it be that when you say "it runs perfectly under eclipse but not AIX" you are taking about 2 different computers ? If so, the one with eclipse is not firewalled, the one where you deploy your app is blocked.

But again, nothing to do with java. It's a level 3 error (TCP layer) of TCP-IP model.

Regards, Stéphane

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top