A solution to the problem of timeout in C million data queries

  • 2020-10-23 20:16:15
  • OfStack

This article explains in detail how to solve the timeout problem of C# million data query and shares it with you for your reference. The specific methods are as follows:

Most of the time, when we use C# to filter 1 piece of information from millions of data, the program connection timeout error often occurs. There are many common errors, such as:
Timeout expired period elapsed to completion of operation or the server and so on

This article explains several common solutions, which can be improved and perfected by those interested.

Of course, the first step is to check whether Connection has not turned off the problem, a common novice will make this mistake, need to carefully check 1 oh, this is not detailed.

. If the sql statement is copied to the query analyzer for execution, if the execution time is already more than 30 seconds, then the following solution is generally adopted:

First, analyze the causes of Timeout. One is that Connection is not closed or SqlConnection.ConnectionTimeout is timed out. The other is that ES35en.CommandTimeout causes SqlCommand.CommandTimeout to get or set the wait time before terminating the attempt and generating an error.

Its default is 30 seconds, you can set it to 0, it means unlimited, but it is better not to set 0, otherwise it will wait indefinitely, just need to set the time for the query analyzer, it is ok

The execution time is not very long, but still the operation time out, then there are also many reasons, 1 commonly there are two, asp.Net application request timeout, or connection pool connection lifetime past, because the default value of the connection pool is 60 seconds, so for the two solutions are:

Resolve application request timeout:

Add the following in ES48en.config:


<system.web> 
<httpRuntime maxRequestLength="102400" executionTimeout="720" />
</system.web> 

executionTimeout: Is the maximum time limit in seconds that requests are allowed to execute
maxRequestLength: Indicates the maximum file upload size supported by ES56en.Net. This restriction can be prevented. Everybody gets it.

Resolve program pool lifecycle issues:

Modify in the database connection string:


database=AA;
uid=sa;
pwd=sa; 
Pooling=true;
MAX Pool Size=1024;
Min Pool Size=1;
Connection Lifetime=60

As for the meaning basically from the English meaning we understand, ha ha. Of course, Min Pool Size=1 has a lot to be said for this setting.

Hopefully this article has helped you with your C# programming.


Related articles: