Network Error: A connection attemp failed

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
pfisupport
Posts: 2
Joined: Tue 04 Dec 2007 19:24

Network Error: A connection attemp failed

Post by pfisupport » Tue 04 Dec 2007 19:43

Hello,

We are using OraDirect .NET V.3.55.23.0

We get the following error on occasion when attempting a connection to Oracle:

CoreLab.Oracle.OracleException: Network error: ( A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond )

The line of code that trips the error is:

oraConn.Open();

oraConn is of type CoreLab.Oracle.OracleConnection

This happens when we set Direct = True and connect directly to the database via IP address. We have tested the same code against dozens of different Oracle databases including 8i, 9i, and 10g and it happens on all of them. If you attempt the connection a second time immediately after the failure, it always connects successfully.

The error is very vague and we can confirm it is not a connectivity issue because other tools connect directly up to these databases instantly and consistently every time.

Any help on this would be appreciated.

Thanks,
Jeff

Paul
Posts: 725
Joined: Thu 28 Oct 2004 14:06

Post by Paul » Thu 06 Dec 2007 13:42

This error comes from TcpClient on attempt to connect to Oracle server on the specified port. Try to connect to this port using a small .NET application.

pfisupport
Posts: 2
Joined: Tue 04 Dec 2007 19:24

Post by pfisupport » Thu 06 Dec 2007 22:32

We are using a .NET application in which this is failing. We are always connecting to the default 1521 port which is always the listening port for these Oracle servers.

How come it always connects successfully the second time right after a failed attempt? It seems to me that the connection is always good since no code has changed and it is successful the second time.

Paul
Posts: 725
Joined: Thu 28 Oct 2004 14:06

Post by Paul » Fri 07 Dec 2007 09:43

Please try the following code

Code: Select all

    private void button1_Click(object sender, EventArgs e) {

      string host = "127.0.0.1";
      int port = 1521;

      TcpClient client = new TcpClient();

      try {

        if (Regex.IsMatch(host + ".", @"^(([0-9]){1,3}\.){4}$")) {
          IPAddress ipAddress = IPAddress.Parse(host);
          client.Connect(ipAddress, port);
        }
        else
          client.Connect(host, port);

        Application.DoEvents();
        this.Text += "Sending ping...";
        client.GetStream().WriteByte(255);
        client.GetStream().Flush();
        this.Text += "Connected.";
      }
      catch (Exception ex) {
        this.Text += "Error occured:" + ex.Message;
      }
      finally {
        if (client != null)
          client.Close();
      }
    }

Post Reply