tags:

views:

65

answers:

2

I have a bit of .NET code that retrieves the results from an Oracle Stored Procedure, using the ADO.NET Library, and populates the results into a DataTable like so:

using System.Data.OracleClient;

public DataTable getData()
{
    OracleConnection conn = new OracleConnection("Data Source=DATASOURCE;Persist Security Info=True;User ID=userID;Password=userPass;Unicode=True;Min Pool Size=1;Max Pool Size=20;Connection Lifetime=300");
    DataTable dt = new DataTable();
    conn.Open();
    try
    {
       OracleCommand oraCmd = new OracleCommand();
       oraCmd.Connection = conn;
       oraCmd.CommandText = "stored_procedure.function_name";
       oraCmd.CommandType = CommandType.StoredProcedure;
       oraCmd.Parameters.Add("cursor", OracleType.Cursor).Direction = ParameterDirection.Output;
       OracleDataAdapter oraAdapter = new OracleDataAdapter(oraCmd);
       oraAdapter.Fill(dt);
    }
    finally
    {
       conn.Close();
       return dt;
    }
}

This code has been working without any issues on several projects I have implemented the code on. However I am running into an issue on a new project, where the Oracle DB machine is actually much slower to respond, and seems to become unresponsive when too many clients begin to access the hardware. What I would like to do is implement some sort of timeout on the oraAdapter.Fill command - as it appears that when the database becomes unresponsive, the .NET application will hang on the 'Fill' method for as long as 10 minutes or more, never reaching the 'finally' codeblock and closing the DB connection.

I am in an environment where I am restricted to using the MSDN Library for connecting to the Oracle Database, so I'm hoping I can do it using the ADO.NET Control.

A: 

It seems you need the CommandTimeout property, not ConnectionTimeout.

Devart
The CommandTimeout property does not seem to function as stated for the System.Data.OracleClient objects. I added this parameter to my OracleCommand object and tested it against queries I know would take a long time, and no error messages were being generated - the application just waits for the response.
John
Try Devart dotConnect for Oracle (http://devart.com/dotconnect/oracle). Our users use the CommandTimeout property without any complaints, and we have a suitable wizard that helps to migrate from OracleClient.
Devart
"I am in an environment where I am restricted to using the MSDN Library for connecting to the Oracle Database." - It appears that the functionality may not be supported.
John
This functionality is not available in Oracle OCI. However, if you are using Direct mode of dotConnect for Oracle, the CommandTimeout is available.
Devart
A: 

The CommandTimeout property does not work using the System.Data.OracleClient .NET 3.5 Provider. It appears that this functionality is not supported without the use of an external library.

John