Setting CommandTimeout in Microsoft's Data Access Application Block (SQLHelper)

4.7k Views Asked by At

I'm using the Data Access Application Block (SQLHelper) to execute SQL against a database. I have one query which takes longer than the default command timeout of 30 seconds. I want to up the timeout, but I don't see any way to do so without cracking open the Application Block. Is there any way to change the CommandTimeout without modifying the SQLHelper class?

3

There are 3 best solutions below

0
On

SQLHelper is replaced by 'Database' in newer versions of DAAB . You can then use DbCommand.SetCommandTimeOut - see here

0
On

If you still are using the old version of DAAB, there are numerous overloads of FillDataset that have command timeout as a parameter.

    public static void FillDataset(string connectionString, CommandType commandType, int commandTimeout, string commandText, DataSet dataSet, string[] tableNames)

    public static void FillDataset(string connectionString, CommandType commandType, int commandTimeout, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)

    public static void FillDataset(string connectionString, string spName, int commandTimeout, DataSet dataSet, string[] tableNames, params object[] parameterValues)

    public static void FillDataset(SqlConnection connection, CommandType commandType, int commandTimeout, string commandText, DataSet dataSet, string[] tableNames)

    public static void FillDataset(SqlConnection connection, CommandType commandType, int commandTimeout, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)

    public static void FillDataset(SqlConnection connection, string spName, int commandTimeout, DataSet dataSet, string[] tableNames, params object[] parameterValues)

    public static void FillDataset(SqlTransaction transaction, CommandType commandType, int commandTimeout, string commandText, DataSet dataSet, string[] tableNames)

    public static void FillDataset(SqlTransaction transaction, CommandType commandType, int commandTimeout, string commandText, DataSet dataSet, string[] tableNames, params SqlParameter[] commandParameters)

    public static void FillDataset(SqlTransaction transaction, string spName, int commandTimeout, DataSet dataSet, string[] tableNames, params object[] parameterValues)
0
On

Well I could not find answer either, so what I did is, I copied the SQLHelper.cd from DAAB in to my project and started using that. ( Its just on file so it was easy )

Now I can change the connection timeout in SQLHelper.cs.

I have no clue on why this is not configurable in DAAB

Manjesh