This documentation is archived and is not being maintained.

IDbCommand.CommandTimeout Property

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

[Visual Basic]
Property CommandTimeout As Integer
[C#]
int CommandTimeout {get; set;}
[C++]
__property int get_CommandTimeout();
__property void set_CommandTimeout(int);
[JScript]
function get CommandTimeout() : int;function set CommandTimeout(int);

Property Value

The time (in seconds) to wait for the command to execute. The default value is 30 seconds.

Exceptions

Exception Type Condition
ArgumentException The property value assigned is less than 0.

Example

[Visual Basic, C#, C++] The following example creates an instance of a derived class, 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 Language Filter 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

IDbCommand Interface | IDbCommand Members | System.Data Namespace | CommandText | Connection | CommandType

Show: