When your app runs into a timeout on a database operation the error message may lead you in a wrong direction to fix things. Which happened to me so this is my little index to the docs.
A sqlConnection has a ConnectionTimeout property. It is a property which determines the maximum number of seconds your code will wait for a connection to the database to open. It is set in the connectionstring to the database
data source=BROCHIS;initial catalog=Indato;integrated security=SSPI;Connect Timeout=60;
Opening the connection does not do anything in the database yet. That is handled by a SqlCommand, which could be part of a SqlDataAdapter. The SqlCommand has aCommandTimeOut. This is a settable property which determines the maximum number of seconds the command is given to execute the sql. By default this is 30 seconds. When you perform something costly in the database this is the one whose value you’ll have to change.
SqlCommand cmd;
if (bigJob)
cmd.CommandTimeout = 60;
For both properties a value of 0 indicates to wait forever. Both properties also apply to non sqlserver database operations. They are defined in IdbConnection and IdbCommand.
Comments
Post a Comment