Change the default SqlCommand CommandTimeout with configuration rather than recompile?

Go To StackoverFlow.com

6

I am supporting an ASP.Net 3.5 web application and users are experiencing a timeout error after 30 seconds when trying to run a report. Looking around the web it seems it's easy enough to change the timeout in the code, unfortunately I'm not able to access the code and recompile. Is there anyway to configure the default for either the web app, the worker process, IIS or the whole machine?

Here is the stack trace up to the point where it's in System.Data in case I'm missing some other problem:

[SqlException (0x80131904): Timeout expired.  The timeout period elapsed prior to completion of the operation or the server is not responding.]
  System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1948826
  System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747
  System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194
  System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392
  System.Data.SqlClient.SqlDataReader.ConsumeMetaData() +33
  System.Data.SqlClient.SqlDataReader.get_MetaData() +83
  System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +297
  System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +954
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +162
  System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
  System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +141
  System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
  System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +10
  System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +130
  System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +162
  System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +115

--Edit

There must be something outside the code itself - I've downloaded the database and run it against the same web site installed on a test server and it runs for longer than 30 seconds and returns the report. I've compared the machine.config and web.config files from the .Net directory on the live and test and they seem the same, compared the two IIS setups, also looked at the SQL Server configuration and the only difference is that the live server is clustered on 64bit W2K3 while the test server is on 32bit.

2009-06-16 14:06
by robertc


14

Unfortunately, everything I've read about this in the past says no, can't be controlled via configuration. Which is a bummer.

2009-06-16 14:10
by Dan F


3

You cannot set the command timeout from the connection string or some external setting, sorry.

Sometimes a driver will interpret the 'timeout' parameter in the connection string as both Connect Timeout and Command Timeout period, but that is technically a "bug". Gotta love the standards.

2009-06-16 18:08
by Radu094


2

The best I know of is you can set a Connection Timeout in the connection string which controls how long ADO will wait while trying to connect to SQL Server and doesn't impact the Command Timeout.

Personally I think there should be a way to change this setting. Assuming the assembly this is in is not strong named your best bet might be to reverse engineer the code modify the source and redeploy the assembly with the new name.

2009-06-16 14:17
by JoshBerke


0

It's not too hard to roll your own though? Just create a custom SqlCommandTimeout setting under AppSettings. If you are already using some sort of SqlCommandFactory to create your SqlCommand or have some sort of SqlCommand base class then you can easily make the change. If not then you probably don't care enough about your code to want to put this in a configuration file anyway.

Regards, James

2010-06-03 05:58
by James Z.
I'm sure it isn't but, as I stated in the question, I didn't have access to the source code. If asking again today this question would probably be on Server Fault - robertc 2010-06-03 10:31
Ads