Asp. Net-a solution to execute a SQL timeout

Source: Internet
Author: User

When we write a program, sometimes to make complex queries, the execution of SQL time is too long, causing the page to execute and prompt the execution of the script timeout, which is we encountered a timeout exception.

Time-out exceptions are in two cases: one is the connection timeout, and one is the execution timeout.
The former is set by Sqlconnection.connectiontimeout.
The latter is set by Sqlcommand.commandtimeout.

Sqlconnection.connectiontimeout
Gets the time to wait before terminating an attempt and generating an error when attempting to establish a connection.
The time, in seconds, to wait for the connection to open. The default value is 15 seconds.

Sqlcommand.commandtimeout
Gets or sets the wait time before terminating an attempt to execute a command and generating an error.
The time, in seconds, to wait for the command to execute. The default is 30 seconds.

This is the method found on the Internet:
Conn.Open ();
SqlCommand sqlcmd=new SqlCommand ();
sqlcmd.commandtimeout=180; The timeout for sqlcmd is 3 minutes
Can be set as needed, if too long, can also be set to 0, when this property is set to 0 means no time limit. This property value should be used with caution. You also need to set the HTTP request run time limit in the Web. config configuration file
<system.web>
</system.web>
Set here for 720 seconds, the front property maxRequestLength is generally used for user upload file limit size! The default is typically 4096KB (4 MB).

Another method I used in the project:
Because the project needs to import at least 200,000 records at a time and classify filtering, calculation, warehousing operations.
Server environment is not very good, mount too many sites, so the entire conversion process may be more than half an hour, at this time, in addition to the server may time out, the browser and server side of the session may time out, and the user does not have to wait for the task to complete. Of course, if you can see the task progress better.

Workaround:

1, the introduction of static objects to record the current operating state, using AJAX real-time display task completion progress, due to the use of static objects, even if the user temporarily left the page to enter the progress is still;

2, the introduction of background threads, the operation of static objects by the thread, can be a good solution to the problem of timeouts.

Original URL: http://www.cnblogs.com/qanholas/archive/2013/02/26/2933625.html

Asp. Net-a solution to execute a SQL timeout

Related Article

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.