T
troylenparker
Hi,
I'm trying to conduct a search operation using C# and ADO.NET. I'm
using a DataAdapter object to execute an Oracle stored procedure, and
this particular command is known to take about 80 seconds to execute.
But I'm trying to set the CommandTimeout parameter so that the command
will time out after a specified number of seconds. For testing, I've
set this value very low...at 5 seconds.
Here is the shortened code (assume that the database connection
"dbConnection" is already open):
// Create the command object.
System.Data.OleDb.OleDbCommand Cmd =
Global.dbConnection.CreateCommand();
Cmd.CommandText = "{Call
DWG_CUSTOMER_ACCESS.CUSTOMER_SEARCH(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
Cmd.CommandTimeout = 5;
/* SET COMMAND PARAMETERS HERE */
// Get a new data set called "Response".
dsReturnSet = new DataSet("Response");
// Try the command query.
try
{
// Get a new data adapter from the command object.
System.Data.OleDb.OleDbDataAdapter daRequest = new
OleDbDataAdapter(Cmd);
// Fill the data set with the response. THIS IS THE LINE THAT
TAKES 80 SECONDS WHEN IT SHOULD TIME OUT AFTER 5 SECONDS.
daRequest.Fill(dsReturnSet);
// If the command is still executing/fetching when code execution
reaches this point, the request timed out.
if (Cmd.Connection.State == ConnectionState.Executing ||
Cmd.Connection.State == ConnectionState.Fetching)
{
Cmd.Cancel();
return ReturnCustomError("SEARCH TIMED OUT.");
}
}
catch (System.Exception E)
{
/* ERROR CATCHING CODE HERE */
}
Why doesn't the command time out after 5 seconds, as I've indicated in
the CommandTimeout parameter? Am I using the property incorrectly? In
this example, I want, after 5 seconds, to stop executing and I'd like
to determine that the command was unsuccessful due to the fact that it
exceeded the timeout, and then return a custom error message as such.
But the command will execute up to the full 80 seconds until it
completes, in effect ignoring the CommandTimeout parameter. Am I doing
something wrong?
I'm trying to conduct a search operation using C# and ADO.NET. I'm
using a DataAdapter object to execute an Oracle stored procedure, and
this particular command is known to take about 80 seconds to execute.
But I'm trying to set the CommandTimeout parameter so that the command
will time out after a specified number of seconds. For testing, I've
set this value very low...at 5 seconds.
Here is the shortened code (assume that the database connection
"dbConnection" is already open):
// Create the command object.
System.Data.OleDb.OleDbCommand Cmd =
Global.dbConnection.CreateCommand();
Cmd.CommandText = "{Call
DWG_CUSTOMER_ACCESS.CUSTOMER_SEARCH(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)}";
Cmd.CommandTimeout = 5;
/* SET COMMAND PARAMETERS HERE */
// Get a new data set called "Response".
dsReturnSet = new DataSet("Response");
// Try the command query.
try
{
// Get a new data adapter from the command object.
System.Data.OleDb.OleDbDataAdapter daRequest = new
OleDbDataAdapter(Cmd);
// Fill the data set with the response. THIS IS THE LINE THAT
TAKES 80 SECONDS WHEN IT SHOULD TIME OUT AFTER 5 SECONDS.
daRequest.Fill(dsReturnSet);
// If the command is still executing/fetching when code execution
reaches this point, the request timed out.
if (Cmd.Connection.State == ConnectionState.Executing ||
Cmd.Connection.State == ConnectionState.Fetching)
{
Cmd.Cancel();
return ReturnCustomError("SEARCH TIMED OUT.");
}
}
catch (System.Exception E)
{
/* ERROR CATCHING CODE HERE */
}
Why doesn't the command time out after 5 seconds, as I've indicated in
the CommandTimeout parameter? Am I using the property incorrectly? In
this example, I want, after 5 seconds, to stop executing and I'd like
to determine that the command was unsuccessful due to the fact that it
exceeded the timeout, and then return a custom error message as such.
But the command will execute up to the full 80 seconds until it
completes, in effect ignoring the CommandTimeout parameter. Am I doing
something wrong?