ADO.NET Connection
and Command Timeout
Provided by: Dave Juth, Senior Systems Architect
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.
If you use older versions of the Microsoft Enterprise
Library's Data Access Application Block, you cannot set a timeout value for
a command object directly. This is another thing to be aware of when
creating a database application with relatively complex queries or large
amounts of data.
Return to the tips page |