加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – 使用sql helper时出现超时问题(Microsoft.Applicatio

发布时间:2020-12-16 09:50:30 所属栏目:asp.Net 来源:网络整理
导读:我在处理长sql查询时遇到超时问题,对于长查询超时的数据集是: static public DataSet Getxxxx(Guid xxxx){ DataSet ds = SqlHelper.ExecuteDataset(ConnectionString,CommandType.StoredProcedure,"GetAllxx",new SqlParameter("@productxx",productxx)); r
我在处理长sql查询时遇到超时问题,对于长查询超时的数据集是:

static public DataSet Getxxxx(Guid xxxx)
{
    DataSet ds = SqlHelper.ExecuteDataset(ConnectionString,CommandType.StoredProcedure,"GetAllxx",new SqlParameter("@productxx",productxx));

    return ds;
}

我在哪里可以设置超时,我使用的是Microsoft应用程序块2.0版.

解决方法

数据访问应用程序块SqlHelper已经是 phased out in favour of ‘Database’,因此您需要显式创建DbCommand并将其传递给Database.ExecuteDataSet.然后,您可以设置 CommandTimeout property,以覆盖默认值30秒.例如这会将超时设置为200秒:

using (DbCommand command = this.Database.GetStoredProcCommand("GetAllxx"))
{
    Database.AddInParameter(command,"@productxx",DbType.Int32,productxx);
    command.CommandTimeout = 200;
    return Database.ExecuteDataSet(command);
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读