Increase SqlCommand.CommandTimeout value from 30 via config file?

Increase SqlCommand.CommandTimeout value from 30 via config file?

Old forum URL: forums.lhotka.net/forums/t/11089.aspx


Gort posted on Wednesday, January 25, 2012

Is it possible to change the default CommandTimeout value of the SqlCommand object via the config file? Our connection string has a timeout value in it which is not honored by the SqlCommand. I don't want to have to manually change every use of the SqlCommand object in order to increase my default timeout from 30 to 60.

tiago replied on Wednesday, January 25, 2012

Although not a CSLA.NET question, the answer is "No, you can't". The timeout in the connection string refers to the lenght of time to make the connection itself, not the length of time to execute queries or commands.

On the other hand, there is a timeout property on the SqlCommand class.

var cmd = new SqlCommand();

cmd.CommandTimeout = 120; // this means 120 seconds

The default command timeout is 30 seconds.

Gort replied on Friday, January 27, 2012

Yes, I understand this. I just didn't want to have to do this on ALL of my calls in order to increase it.  I guess I may not have a choice.

Copyright (c) Marimer LLC