Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

getting error during getConnection

1 view
Skip to first unread message

ilyak

unread,
Dec 18, 2002, 11:55:47 PM12/18/02
to
Using JDBC driver for Microsoft SQL Server 2000 I am getting
"error establishing socket". It happens when client runs on a different
than SQL Server node. When client and server are on same node everything
works fine.
MS SQL Server 2000 with SP2 runs on NT 5.0 Server machine.
Client runs on NT 2000 Workstation with JRE 1.4.1.

Actually I tried a couple more JDBC drivers with same result.

Am I missing something?

Thank you very much,
Ilya

I am using the following connection properties:
url=jdbc:microsoft:sqlserver://POTAMUS:1433
driver=com.microsoft.jdbc.sqlserver.SQLServerDriver
user=me
password=password

And code like this:

/**
* Creates a new connection..
*
* @throws ClassNotFoundException
* @throws InstantiationException
* @throws IllegalAccessException
* @throws SQLException
*/
private void createConnections(String driver, String url, String user,
String password)
throws ClassNotFoundException, InstantiationException,
IllegalAccessException, SQLException
{
Class cl = Class.forName(drivver);
if (cl != null)
{
cl.newInstance();
}
else
{
throw new ClassNotFoundException("java.lang.ClassNotFoundException: " +
driver);
}
...
try
{
Connection con = DriverManager.getConnection(url, username, password);
}
catch (SQLException e)
{
throw new SQLException(e.getMessage() + " - please check database
connection parameters. ");
}
}


Joseph Weinstein

unread,
Dec 19, 2002, 10:59:57 AM12/19/02
to ilyak

ilyak wrote:

> Using JDBC driver for Microsoft SQL Server 2000 I am getting
> "error establishing socket". It happens when client runs on a different
> than SQL Server node. When client and server are on same node everything
> works fine.
> MS SQL Server 2000 with SP2 runs on NT 5.0 Server machine.
> Client runs on NT 2000 Workstation with JRE 1.4.1.
>
> Actually I tried a couple more JDBC drivers with same result.
>
> Am I missing something?

Does it happen everytime? Try compiling and running this little
program on your remote node:

isAnythingListeningOn POTAMUS 1433

import java.io.*;
import java.net.*;

public class isAnythingListeningOn
{
public static void main(String argv[])
throws Exception
{
if (argv.length != 2)
{
System.out.println("Usage: isAnythingListeningOn <host> <port>");
System.out.println("eg:\n% java isAnythingListeningOn myMachine 1433");
System.exit(0);
}

try
{
System.out.println("\nTrying to open a socket with host "
+ argv[0] + " and port " + argv[1] + " ...");
Socket socket = new Socket(argv[0],(new Integer(argv[1]).intValue()));
System.out.println("\nYes, there is, we got a socket.");
socket.close();
}
catch (Exception e)
{
System.out.println("We failed to open a socket. Here's why:\n");
e.printStackTrace();
System.out.println("\n(Either there is no machine named '" + argv[0]
+ "' or\nnothing is listening there on port "
+ argv[1] +")\n");

ilyak

unread,
Dec 25, 2002, 12:03:02 PM12/25/02
to
Thanks for reply, Joseph

import java.io.*;
import java.net.*;

public class isAnythingListeningOn
{
public static void main(String argv[])
throws Exception
{
if (argv.length != 2)
{
System.out.println("Usage: isAnythingListeningOn <host> <port>");
System.out.println("eg:\n% java isAnythingListeningOn myMachine
1433");
System.exit(0);
}

try
{
System.out.println("\nTrying to open a socket with host "
+ argv[0] + " and port " + argv[1] + " ...");
Socket socket = new Socket(argv[0],(new Integer(argv[1]).intValue()));
System.out.println("\nYes, there is, we got a socket.");
socket.close();
}
catch (Exception e)
{
System.out.println("We failed to open a socket. Here's why:\n");
e.printStackTrace();
System.out.println("\n(Either there is no machine named '" + argv[0]
+ "' or\nnothing is listening there on port "
+ argv[1] +")\n");
}
}
}


isAnythingListeningOn POTAMUS 1433

The program failed with message and stack trace:

Trying to open a socket with host POTAMUS and port 1433 ...


We failed to open a socket. Here's why:

java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at
java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:426)
at java.net.Socket.connect(Socket.java:376)
at java.net.Socket.<init>(Socket.java:291)
at java.net.Socket.<init>(Socket.java:119)
at isAnythingListeningOn.main(isAnythingListeningOn.java:22)

(Either there is no machine named 'POTAMUS' or
nothing is listening there on port 1433)

In fact MS SQL Server is running on POTAMUS and listening port 1433
(I checked it in network utility)
I can perfecty connect and do whatever I want with enterprise manager
or query analizer on client machine and can not connect through Java.
Any idea why?

Mark Hansen

unread,
Dec 25, 2002, 2:39:26 PM12/25/02
to
ilyak wrote:
> Thanks for reply, Joseph
>
[ code snippet snipped ;-)]


>
> The program failed with message and stack trace:
>
> Trying to open a socket with host POTAMUS and port 1433 ...
> We failed to open a socket. Here's why:
>
> java.net.ConnectException: Connection refused: connect
> at java.net.PlainSocketImpl.socketConnect(Native Method)
>

> (Either there is no machine named 'POTAMUS' or
> nothing is listening there on port 1433)
>
> In fact MS SQL Server is running on POTAMUS and listening port 1433
> (I checked it in network utility)
> I can perfecty connect and do whatever I want with enterprise manager
> or query analizer on client machine and can not connect through Java.
> Any idea why?

Perhaps the java application is having a problem with the host
name. Try replacing the host name "POTAMAS" with that machine's
IP address.

"Connection Refused" means there is nothing listening on that
port, period. So either it's not getting the host name right,
or the port right, but one of themis likely to be wrong.

The only other thing that I can think of is a Java Security Policy,
but that would throw a different exception, so I think it is ruled
out.

From the same client machine, try using telnet, with the host and
port set to POTAMAS and 1433, and see what it does. You won't be
able to talk to the SQL Server, but you should, at least, get a
connection. If it also reports connection refused, that's further
evidence that no one is really listening on port 1433.

Have you run the "isqlw.exe" client, and asked it to connect to
POTAMAS/1433? This would be a good test also.

Good luck.

0 new messages