Setting "Execution Time Out"

If you find an error with the message "Execution Time Out", was one reason is the connection to the database that is too long.

By default, a web server in the Timeout setting is 30 seconds max. Once there is a database connection that is more than 30 seconds, then the error message will be sent.

Then how do we want to enlarge this timeout, for example 60 seconds. The following piece of c# code themselves:

using (SqlConnection conn = new SqlConnection("ConnectionString"))

{

conn.Open();

SqlCommand cmd = new SqlCommand(SpName, conn);

cmd.CommandType = CommandType.StoredProcedure;

cmd.CommandTimeout = 60; //add timeout here

SqlParameter[] sqlParameter = new SqlParameter[2];

sqlParameter[0] = new SqlParameter("@MhsId", SqlDbType.Char, 10);

sqlParameter[0].Direction = ParameterDirection.Input;

sqlParameter[0].Value = mhsId;

sqlParameter[1] = new SqlParameter("@PriodId", SqlDbType.Char, 25);

sqlParameter[1].Direction = ParameterDirection.Input;

sqlParameter[1].Value = periodId;

cmd.Parameters.AddRange(sqlParameter);

using (SqlDataReader sqlDataReader = cmd.ExecuteReader())

{

}

}

Ok, may it helps

Thanks

No comments:

Post a Comment