本文介绍了超时问题使用SQL帮手时(Microsoft.ApplicationBlocks.Data)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我长的SQL查询交易时有超时问题,数据集这timesout长的查询是:

I am having timeout issues when dealing with long sql queries, the Dataset which timesout for long queries is :

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

    return ds;
}

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

Where can i set timeout , I am using Microsoft application block version 2.0.

推荐答案

数据访问应用程序块提供SQLHelper 已赞成数据库淘汰,所以你需要显式地创建一个的DbCommand ,并通过它传递给 Database.ExecuteDataSet 。然后,您可以设置,覆盖了30秒的默认。例如这将超时时间设置为200秒:

The Data Access Application Block SqlHelper has been phased out in favour of 'Database', so you'll need to explicitly create a DbCommand and pass it through to Database.ExecuteDataSet. You can then set the CommandTimeout property, to override the default of 30 seconds. e.g. this sets the timeout to 200 seconds:

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

这篇关于超时问题使用SQL帮手时(Microsoft.ApplicationBlocks.Data)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 14:27