Tutorial :How can I set a connection lifespan timeout for an OracleDataAdapter executing a stored procedure using the Fill Method?


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.


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.


It seems you need the CommandTimeout property, not ConnectionTimeout.

Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Next Post »