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.