SqlCommand..::.CommandTimeout Property Home
This page is specific to:.NET Framework Version:1.12.03.03.54.0
.NET Framework Class Library
SqlCommand..::.CommandTimeout Property

Gets or sets the wait time before terminating the attempt to execute a command and generating an error.

Namespace:  System.Data.SqlClient
Assembly:  System.Data (in System.Data.dll)
Syntax

'Usage

Dim instance As SqlCommand
Dim value As Integer

value = instance.CommandTimeout

instance.CommandTimeout = value

'Declaration

Public Overrides Property CommandTimeout As Integer

Property Value

Type: System..::.Int32
The time in seconds to wait for the command to execute. The default is 30 seconds.

Implements

IDbCommand..::.CommandTimeout
Remarks

A value of 0 indications no limit, and should be avoided in a CommandTimeout because an attempt to execute a command will wait indefinitely.

NoteNote:

The CommandTimeout property will be ignored during asynchronous method calls such as BeginExecuteReader.

CommandTimeout has no effect when the command is executed against a context connection (a SqlConnection opened with "context connection=true" in the connection string).

NoteNote:

This property is the cumulative time-out for all network reads during command execution or processing of the results. A time-out can still occur after the first row is returned, and does not include user processing time, only network read time.

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0
See Also

Reference

Other Resources

Community Content

Values
Added by:Ananth Ramasamy Meenachi www.msarm.com
Value is in seconds NOT milliseconds.

For Example:

1 minute timeout = set 60 s
3 minutes timeout = set 180 s
Bug in text
Added by:TopOnePercent
Text says "A value of 0 indications no limit," should say "A value of 0 indicates no limit"
Global Change
Added by:Thomas Lee
Is there any way to change default setting globally for a web application, like in web.config, or machine.config?

[tfl - 18 07 09] Thanks for your post. However, for support questions like this, you shouls use the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&

Bummer!
Added by:Marc Schluper

System.Data.SqlClient.SqlCommand

is a sealed class. Therefore I see no way to set the CommandTimeout to a higher value for all commands used in an application, and this is a bummer. The default of 30 seconds is not adequate: see http://support.microsoft.com/kb/305635/ which explains that the database may never autogrow if each command to add data times out (because the autogrow takes longer than 30 seconds).
What did I miss?
Added by:Thomas Lee

Setting command's timeout prop even to 1s seems to have no effect. Looong query still gets executed fine when the timeout expired exception should be thrown.

Any ideas?


[tfl - 18 07 09] Thanks for your post. However, for support questions like this, you should use the MSDN Forums at http://forums.microsoft.com/msdn or the MSDN Newsgroups at http://www.microsoft.com/communities/newsgroups/en-us/. You are much more likely get a quicker response using the forums than through the Community Content. For specific help about:
Visual Studio : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.vstudio%2C&
.NET Framework : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public.dotnet.framework
All Public : http://groups.google.com/groups/dir?sel=usenet%3Dmicrosoft.public%2C&

© 2009 Microsoft Corporation. All rights reserved.   Terms of Use | Trademarks | Privacy Statement
Page view tracker
Rate the Lightweight library
x
Lightweight builds on ScriptFree (loband) by adding features you've requested: a SearchBox and default code language selection.
Do you like the SearchBox?
Do you like the tabbed code blocks?
How useful is this topic?
Tell us more.
Thanks
x
You're helping to improve MSDN Online.
Feedback
Switch View
Classic
Lightweight Beta
ScriptFree
Switch View