SqlConnection con = new SqlConnection("server=.;database=myDB;uid=sa; pwd=password;")改为:
SqlConnection con = new SqlConnection("server=.; database=myDB;uid=sa;pwd=password;Connect Timeout=500")似乎没效果。依然运行30秒即报超 时!
SqlConnection的属性有个ConnectionTimeout,
SqlConnection con = new SqlConnection("server=.;database=myDB;uid=sa;pwd=;");
con.ConnectionTimeout = 180; //报错,属性ConnectionTimeout 为只读!尝试失败,再接着看command对象属性,发现其也有类似属 性!CommandTimeout设置一下:
SqlCommand cmd = new SqlCommand();
cmd.CommandTimeout = 180; 再运行,即解决,这里设置的时间的180秒,即三分钟!可根据需要设置,如果过长,也可以设置为0,当此属性设置为0时表示不限制时间。此属性值应该慎 用。还需要在Web.config配置文件中设置http请求运行时限间
<system.web>
<httpRuntime maxRequestLength="102400" executionTimeout="720" />
</system.web>
转载于:https://www.cnblogs.com/ice5/archive/2010/07/06/1772352.html