This documentation is archived and is not being maintained.

OdbcCommand.CommandTimeout Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

Gets or sets the wait time before terminating an 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

IDbCommand.CommandTimeout

Exceptions

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

Remarks

A value of zero (0) specifies no limit to the wait time, rather than no wait time, and therefore should be avoided.

Example

[Visual Basic, C#, C++] The following example creates an OdbcCommand and sets some of its properties.

[Visual Basic] 
Public Sub CreateMyOdbcCommand()
    Dim mySelectQuery As String = "SELECT * FROM Categories ORDER BY CategoryID"
    Dim myCommand As New OdbcCommand(mySelectQuery)
    myCommand.CommandTimeout = 20
End Sub

[C#] 
public void CreateMyOdbcCommand() 
{
   string mySelectQuery = "SELECT * FROM Categories ORDER BY CategoryID";
   OdbcCommand myCommand = new OdbcCommand(mySelectQuery);
   myCommand.CommandTimeout = 20;
}

[C++] 
public:
    void CreateMyOdbcCommand()
    {
        String* mySelectQuery = S"SELECT * FROM Categories ORDER BY CategoryID";
        OdbcCommand* myCommand = new OdbcCommand(mySelectQuery);
        myCommand->CommandTimeout = 20;
    };

[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

See Also

OdbcCommand Class | OdbcCommand Members | System.Data.Odbc Namespace | Connection | CommandText | CommandType | CommandTimeout

Show: