Timeout issue when using sql helper(Microsoft.ApplicationBlocks.Data)

谁说胖子不能爱 提交于 2019-12-14 03:46:31

问题


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;
}

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


回答1:


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);
}


来源:https://stackoverflow.com/questions/8882369/timeout-issue-when-using-sql-helpermicrosoft-applicationblocks-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!