Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between SqlCommand.CommandTimeout and SqlConnection.ConnectionTimeout?

Is there any difference between SqlCommand.CommandTimeout and SqlConnection.ConnectionTimeout in .NET?

like image 771
Dhanapal Avatar asked May 11 '09 08:05

Dhanapal


People also ask

What is CommandTimeout?

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.

What is Sqlcommand CommandTimeout property used for?

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

Is CommandTimeout in seconds or milliseconds?

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.

What is the default connection timeout for Sqlconnection?

The default value is 15 seconds.


1 Answers

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.

like image 58
Jon Skeet Avatar answered Sep 20 '22 17:09

Jon Skeet