Increasing timeout for a single stored procedure

Posts   
 
    
sunpig
User
Posts: 2
Joined: 21-Mar-2006
# Posted on: 21-Mar-2006 17:34:58   

Hi,

Working with the adapter scenario (1.0.2005.1, generating C# for .NET 1.1), I've got one stored procedure that takes a long time (~ 2 minutes) to return a set of results. By using the RetrievalProcedures class, though, I can't change the CommandTimeOut property of the DataAccessAdapter, because the adapter is created in the generated code.

I can copy the necessary code out of RetrievalProcedures and put it in a separate class:


DataTable dt = new DataTable("GetPagedFilteredRows");
using(DataAccessAdapter adapter = new DataAccessAdapter()) 
{
    SqlParameter[] parameters = new SqlParameter[5];
    parameters[0] = new SqlParameter("@DataAnalysisTableID", SqlDbType.Int, 0, ParameterDirection.Input, true, 10, 0, "",  DataRowVersion.Current, dataAnalysisTableId);
    // ... (more parameters here)

    // This proc may take a while: set a higher timeout than normal
    adapter.CommandTimeOut = 180;
    bool hasSucceeded = adapter.CallRetrievalStoredProcedure("prcGetPagedFilteredRows", parameters, dt);
}

But now I have a chunk of database-specific, non-generated code to maintain. If I change the procedure at some point in the future, I have to remember to come back to this class and update the code manually.

Is there a better way of changing the Timeout for some (but not all) stored procedures?

-Martin.

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 22-Mar-2006 02:46:34   

If you want to use an existing DataAccessAdapter you can specify that existing adapter in the method call as an extra parameter and set that adapters CommandTimeout property to 180 to be safe.

sunpig
User
Posts: 2
Joined: 21-Mar-2006
# Posted on: 22-Mar-2006 11:08:47   

Doh! That's totally obvious. Thanks for pointing it out!

-Martin.