Specify Default SQL CommandTimeout for Data Access

Topics: Data Access Application Block
Apr 17, 2008 at 4:48 PM
I've seen posts from 2 - 3 years ago requesting an enterprise library DAAB feature that supports specifying a default, global CommandTimeout for EnterpriseLibrary.Data.Sql methods.

I'm now using EntLib 3.1, but am not able to tell if this feature is available. Was it implemented? If not, any "best practices" or suggestions for implementing a global, config-file driven CommandTimeout?

Example: I'd like to be able to set default CommandTimeout once when I instantiate my Database object, and then have it apply to all calls of ExecuteReader method.

We have hundreds of methods in a SqlDataProvider class implementing a data provider pattern and I do not want to have to set the command timeout explicitly in every method.

Thanks in advance for any insight.
Apr 9, 2010 at 11:56 PM

I was looking for this feature as well for 3.1.  I think the only way I can do this is using DbCommand.CommandTimeout property of the ADO.Net.  The default is set by ADO.Net to 30 seconds.

http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlcommand.commandtimeout.aspx
Apr 12, 2010 at 1:56 AM
Edited Apr 12, 2010 at 1:56 AM

It's not supported out-of-the-box but one thing I could think of is to create a wrapper for the methods from the Database class that returns a DbCommand object.  Inside that method, after creating the DbCommand object using the method from the Database object, set first the CommandTimeOut property based on what it set in the config file before returning that object.

 

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.

entlib.support@avanade.com