System. Data. sqlclient. sqlexception: the timeout has reached-Solution

Source: Internet
Author: User

I made a daily statistical report page for my company a few days ago. Because the amount of data to be queried is huge, it is still slow to execute the query in the stored procedure. Even more depressing is that when I test this page, always error -- system. data. sqlclient. sqlexception: the timeout has reached.

The solution consists of two steps:

1. Insert the following sentence in the <system. Web> label in Web. config:

<Httpruntime maxrequestlength = "2097151" executiontimeout = "720000"/>

The maximum value of maxrequestlength seems to be 2097151, and an error will be reported if it is too large. The executiontimeout value is completely gibberish, but at least no error has been reported.

2. Add the following sentence to the database connection code:

String constr = "Data Source = ......; Initial catalog = ......; Persist Security info = true; user id = ......; Password = ...... ";
Sqlconnection conn = new sqlconnection (constr );
Sqlcommand cmd = conn. createcommand ();
Cmd. commandtext = This. SQL;
Cmd. commandtimeout = 10000; // Add this sentence
Conn. open ();
Sqldataadapter adapter = new sqldataadapter (CMD );
Dataset DS = new dataset ();
Adapter. Fill (DS );
Conn. Close ();

If there is still a problem after this modification, you have to consider whether you want to change your server ~...... Haha!

 

Note: This article is original works, reprint please indicate the source: http://www.cnblogs.com/luzx

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.