Asp.Net summary of various timeout issues

  • 2020-05-26 08:14:58
  • OfStack


In the process of database or request operation, if the selected period of time is too short or the amount of operation data is too large, the problem of "request timeout" will be encountered. Many solutions are provided on the network, but they are generally not perfect. Based on personal experience and reference network solutions, they are summarized as follows:

According to the error type, it can be divided into the following situations
1: Asp.net request timeout
2: IIS request timeout
3: database connection timeout
4: database operation timeout
5: application pool recycling (low)
6: service request timeout such as Webservice

Let's deal with the situation 11 above
1: Asp.net request timeout
The http request timeout can be configured globally in webconfig (in seconds, default is 90 seconds) as follows
< system.web >
< httpRuntime maxRequestLength="102400" executionTimeout="180" / >
system. web >

2: IIS request timeout
Directly go to IIS to set: IIS- website - property to set a large value, but not too large, which will be analyzed in a case by case basis.

3: database connection timeout
Configure 1 when configuring the database connection string
< connectionStrings >
< add name="MarketingMate" connectionString="Data Source=192.168.1.1; Database=MarketingMate; User Id=sa; Password=123; Connect Timeout=30;Min Pool Size=16;Max Pool Size=100;"
providerName = "System. Data. SqlClient" / >
connectionStrings >

4. Database operation timeout
Currently, there is no global setting method for database operation timeout, only the CommandTimeOut property of class Command can be set (in seconds, default is 30 seconds).
context. CommandTimeout = 180;

5: the situation of application pool recovery (bottom) is very low, please set it as appropriate
The application pool will recycle the thread in 1 fixed time, you can set it directly: the application pool -- property -- recycle the worker process

6: the service request of Webservice is timed out (this is a solution provided by referring to the Internet, which I have never encountered)
Extends the timeout limit for the proxy class to 90 seconds by default, specifying a timeout before calling the method.
[csharp]YourWebService yws = new YourWebService(); yws. Timeout = 1200000; //20 minutes, in milliseconds [/csharp]
If the Timeout property is set to Timeout.Infinite, there is no timeout for the request. Even though the XML Web services client can set the Timeout property to no timeout, the Web server can still timeout requests on the server side.

Related articles: