System.Data.SqlClient Namespace SqlCommand Class
Sets or retrieves the wait time before terminating the attempt to execute a command and generating an error.
Script |
SqlCommand.CommandTimeout [ = intTimeout ] |
intTimeout |
The time ( in seconds ) to wait for the command to execute. |
The property is read/write with a default value of 30.
IDbCommand.CommandTimeout
Exception Type |
Condition |
ArgumentException |
The property value assigned is less than
0. |
A value of 0 indicates no limit, and should be avoided in a CommandTimeout because an attempt to execute a command will wait indefinitely.
The following example illustrates how the CommandTimeout property can be set.
void setSqlCommand ( ) {
SqlCommand myCommand = new SqlCommand ( );
myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID";
myCommand.CommandTimeout = 15;
}
Public Sub setSqlCommand ( )
Dim myCommand As New SqlCommand ( )
myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"
myCommand.CommandTimeout = 15
End Sub |
|
C# |
VB |
SqlCommand Members CommandText Connection CommandType