Connection Timeout和Command Timeout

Original: Connection Timeout and Command Timeout

Each time a database connection, we sometimes encounter connection timeout or command timeout, the two time-out is not the same. In ADO.NET example, when the client and server connection timeout condition encountered are the following categories:

When obtaining a connection from the connection pool when hit out.

When establishing a new connection (not from the connection pool), ran out.

When sending a command (command) to SQL Server, time out.

When the transmission command (with connection string "context connection = true" property) to SQL Server, timeout.

When sending a command (implicitly) it is not displayed when the SQL Server, run into a timeout.

When executing asynchronous commands, (BeginExecute) come out.

When from the server, acquires row hit out.

When using Bulk copy mode, upload the data, hit out.

These timeouts mainly be controlled by the Connect Timeout connection string and SqlCommand.CommandTimeout. The first two are determined by the login timeout when Connection Timeout timeout, followed by several command timeout is determined by the Command Timeout when a timeout.

 

SqlConnection.ConnectionTimeout:
1. Description: Get termination try to establish a connection attempt and generating an error before the time to wait.
2. Default: connection open waiting time (in seconds). The default is 15 seconds.
3. Note: The value 0 indicates unlimited
4. A read-only

The SqlCommand.CommandTimeout
1. Description: Gets or sets the termination attempt to execute a command and generating the waiting time before the error.
2. Default: command execution waiting time (in seconds). The default is 30 seconds.
3. Note: The value of 0 indicates unlimited, should be avoided in a CommandTimeout value 0, otherwise it will wait indefinitely for the command.
4. readable and writable

 

Special attention:
"Timeout expired before the operation is completed or the timeout period elapsed server is not responding."
Similarly such errors, or generally SqlCommand.CommandTimeout SqlBulkCopy.BulkCopyTimeout time expires, instead SqlConnection.ConnectionTimeout.

Guess you like

Origin www.cnblogs.com/lonelyxmas/p/12147848.html