When I first arrived on Monday, the company asked me to solve the problem that the system had been residual. One of the channels could not be opened, and an error was reported, "the timeout time is up. The time-out period has expired or the server has not responded before the operation is completed"
The initial analysis reason is that the connection timed out during the MSSQL operation. I did not pay attention to this issue before, probably because I set the connection time limit in the configuration file and found a solution online, most of them are solved in database connection strings.
SqlConnection con = new SqlConnection ("server =.; database = myDB; uid = sa; pwd = password ;")
Changed:
SqlConnection con = new SqlConnection ("server =.; database = myDB; uid = sa; pwd = password; Connect Timeout = 500 ")
It seems ineffective. If it is still running for 30 seconds, a timeout is reported!
Suddenly it seems that you can specify the con attribute in the Connection database code. There is a ConnectionTimeout, SqlConnection con = new SqlConnection ("server = .; database = myDB; uid = sa; pwd = ;");
Con. ConnectionTimeout = 180; // an error is reported. The ConnectionTimeout attribute is read-only!
The attempt failed, and then looked at the command object property, and found that it also has a similar property! CommandTimeout settings:
SqlCommand cmd = new SqlCommand ();
Cmd. CommandTimeout = 180;
Run again to solve the problem. The time set here is 180 seconds, that is, three minutes! You can set it as needed. If it is too long, you can also set it to 0. When this attribute is set to 0, there is no time limit. This attribute value should be used with caution. You also need to set the time limit for running http requests in the Web. config configuration file.
<System. web>
<HttpRuntime maxRequestLength = "102400" executionTimeout = "720"/>
</System. web>
The value is set to 720 seconds. The preceding maxRequestLength attribute is generally used to limit the size of uploaded files! The default value is generally 4096 KB (4 MB ).