Sqlconnection con = new sqlconnection ("Server =.; database = mydb; uid = sa; Pwd = password ;")
Changed:
Sqlconnection con = new sqlconnection ("Server =.; database = mydb; uid = sa; Pwd = password; Connect timeout = 500 ")
It seems ineffective. If it is still running for 30 seconds, a timeout is reported!
Suddenly it seems that you can connect to the databaseCodeIndicates that the con attribute has a connectiontimeout,
Sqlconnection con = new sqlconnection ("Server =.; database = mydb; uid = sa; Pwd = ;");
Con. connectiontimeout = 180; // an error is reported. The connectiontimeout attribute is read-only!
The attempt failed, and then looked at the command object property, and found that it also has a similar property! Commandtimeout settings:
Sqlcommand cmd = new sqlcommand ();
Cmd. commandtimeout = 180;
Run again to solve the problem. The time set here is 180 seconds, that is, three minutes! You can set it as needed. If it is too long, you can also set it to 0. When this attribute is set to 0, there is no time limit. This attribute value should be used with caution.
You also need to set the time limit for running HTTP requests in the web. config configuration file.
<System. Web>
<Httpruntime maxrequestlength = "102400" executiontimeout = "720"/>
</System. Web>
The value is set to 720 seconds. The preceding maxrequestlength attribute is generally used to limit the size of uploaded files! The default value is generally 4096 KB (4 MB ).