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