Is there any difference between SqlCommand.CommandTimeout
and SqlConnection.ConnectionTimeout
in .NET?
The CommandTimeout property sets or returns the number of seconds to wait while attempting to execute a command, before canceling the attempt and generate an error. Default is 30.
Gets or sets the wait time (in seconds) before terminating the attempt to execute a command and generating an error.
It seems that people are confused as to whether this is seconds or milliseconds. The documentation states that the timeout is in seconds. A 1-minute timeout seems reasonable for most queries.
The default value is 15 seconds.
Yes. CommandTimeout
is how long a single command can take to complete. ConnectionTimeout
is how long it can take to establish a connection to the server to start with.
For instance, you may be executing relatively long-running queries - it's perfectly okay for them to take 10 minutes to complete, but if it took 10 minutes to make the connection to start with, you'd know that something was badly wrong.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With