Gets or sets the wait time before terminating the attempt to execute a command and generating an error.
[Visual Basic] Public Overridable Property CommandTimeout As Integer Implements _ IDbCommand.CommandTimeout [C#] public virtual int CommandTimeout {get; set;} [C++] public: __property virtual int get_CommandTimeout(); public: __property virtual void set_CommandTimeout(int); [JScript] public function get CommandTimeout() : int; public function set CommandTimeout(int);
Property Value
The time (in seconds) to wait for the command to execute. The default is 30 seconds.
Implements
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentException | The property value assigned is less than 0. |
Remarks
A value of 0 indicates no limit, and should be avoided in a CommandTimeout because an attempt to execute a command will wait indefinitely.
Example
[Visual Basic, C#, C++] The following example creates a SqlCommand and sets some of its properties.
[Visual Basic] Public Sub CreateMySqlCommand() Dim myCommand As New SqlCommand() myCommand.CommandTimeout = 15 myCommand.CommandType = CommandType.Text End Sub [C#] public void CreateMySqlCommand() { SqlCommand myCommand = new SqlCommand(); myCommand.CommandTimeout = 15; myCommand.CommandType = CommandType.Text; } [C++] public: void CreateMySqlCommand() { SqlCommand* myCommand = new SqlCommand(); myCommand->CommandTimeout = 15; myCommand->CommandType = CommandType::Text; }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework
See Also
SqlCommand Class | SqlCommand Members | System.Data.SqlClient Namespace | CommandText | Connection | CommandType
