您的位置:首页 > 数据库

System.Data.SqlClient.SqlException: 超时时间已到---解决之道

2010-04-27 15:22 405 查看
前几天在给公司做一个统计日报页面,因为要查询的数据量非常巨大,改为存储过程来执行查询依然速度缓慢,更为郁闷的是当我测试此页面的时候,总是出错——System.Data.SqlClient.SqlException: 超时时间已到。

解决之道分为两步:

1.在web.config中的<system.web>标签中插入下面这句:

<httpRuntime maxRequestLength="2097151" executionTimeout="720000"/>

maxRequestLength的最大值好像就是2097151了,再大了会报错。executionTimeout的值完全是我乱写的,但至少还没报错。

2.在连接数据库的代码中加入如下一句:

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; //要加这一句
conn.Open();
SqlDataAdapter adapter = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
adapter.Fill(ds);
conn.Close();

如果这样修改之后还有问题,那你真得考虑是不是要更换你的服务器了~……呵呵!

注:此文章属原创作品,转载请注明出处:http://www.cnblogs.com/luzx
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐