The timeout time has reached. The timeout time has passed before the operation is completed or the server has not responded

Source: Internet
Author: User
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 ).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.