Surendra Sharma

Surendra Sharma

Search This Blog

Wednesday, June 12, 2013

Set Command Timeout for SqlCommand

If you are running store procedure or SQL query from C# which is taking long time to run, set Command-timeout of SQL Command object in seconds.
For this, you don’t need to set connection timeout in connection string in config file.
A value 0 means no limit.
Suppose you want to set command time out for 3 hour = 3 * 60 * 60 = 10800 sec
SqlCommand objSqlCommand = new SqlCommand();

objSqlCommand.CommandTimeout = 10800; 

No comments:

Post a Comment