Home » SQL Server

ADO.NET Default CommandTimeOut

Dear Techies

SqlCommand.CommandTimeout has a default value of 30 seconds. I know that we can set it in our code. Is there any way to alter this default value by chaning some configuration files which is part of the .NET framework so that I dont have to touch the code.


Appreciate your inputs.


Thank You



Jayaraj Sivadasan



3 Answers Found


Answer 1

The connection string will help you in that. set  the time out in your connection string.

Answer 2

The timeout in the connectionstring is for how long we wait for the connection to sucessfully open. Not for the actual command to complete.

AFAIK there is no config files  provided by .Net itself to control the commandtimeout. But there is nothing to keep you from creating your own config

file and read a value from there. This file can then be edited from outside of the code.



Answer 3

Yes its my mistake Michael. Thanks for the correction Michael.


The SqlConnection and SqlCommand objects each have a property to set  a timeout value (ConnectionTimeout and CommandTimeout, respectively). You should note that the SqlConnection.ConnectionTimeout is the time allowed to establish a connection, and the SqlCommand.CommandTimeout is the time allowed to return data from a query or complete a data operation. The connection object's timeout is sometimes mistaken as a way to control how long an application waits for a query result, which is not the case and can be a "gotcha" for developers.



Please mark the response as answers if it solves your question or vote as helpful if you find it helpful. My Blog: http://ashishkhandelwal.arkutil.com


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure