我有点小问题,希望有人能给我一些建议.我正在运行一个SQL命令,但由于有大量数据,这个命令似乎需要大约2分钟才能返回数据.但是默认连接时间是30秒,我如何增加这个时间,并将其应用到这个命令中?

public static DataTable runtotals(string AssetNumberV, string AssetNumber1V)
{
    DataTable dtGetruntotals;

    try
    {
        dtGetruntotals = new DataTable("Getruntotals");

        //SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 6);
        //AssetNumber.Value = AssetNumberV; 

        SqlParameter AssetNumber = new SqlParameter("@AssetNumber", SqlDbType.VarChar, 10);
        AssetNumber.Value = AssetNumberV;

        SqlParameter AssetNumber1 = new SqlParameter("@AssetNumber1", SqlDbType.VarChar, 10);
        AssetNumber1.Value = AssetNumber1V;

        SqlCommand scGetruntotals = new SqlCommand("EXEC spRunTotals @AssetNumber,@AssetNumber1 ", DataAccess.AssetConnection); 
        // scGetruntotals.Parameters.Add(AssetNumber);
        scGetruntotals.Parameters.Add(AssetNumber);
        scGetruntotals.Parameters.Add(AssetNumber1);

        SqlDataAdapter sdaGetruntotals = new SqlDataAdapter();
        sdaGetruntotals.SelectCommand = scGetruntotals;
        sdaGetruntotals.Fill(dtGetruntotals);

        return dtGetruntotals;
    }
    catch (Exception ex)
    {
        MessageBox.Show("Error Retriving totals Details: Processed with this error:" + ex.Message);
        return null;
    }
}

推荐答案

由于存在大量数据,因此该命令大约需要2分钟才能返回数据

可能是糟糕的设计.考虑在这里使用分页.

默认连接时间为30秒,如何增加

由于命令面临超时,因此需要增加sql command的超时时间.可以像这样在命令中指定它

// Setting command timeout to 2 minutes
scGetruntotals.CommandTimeout = 120;

Sql相关问答推荐

查询将查找将标记设置为user2的用户

将有界时间周期作为阶跃函数,其中周期开始返回1,周期结束返回0

具有2个共享列的两个表的Amazon RSQL合并

Oracle SQL根据列中的条件 Select 最大记录数

用于过滤嵌套对象或数组中的JSON数据的WHERE条件

基于多参数的SQL Server条件过滤

如何用HeidiSQL在Firebird中设置超时?

每个学校 Select N个最新的行,但跳过同一学生的重复行

在SQL查询中查找客户端的最短日期比较列和多行

将 jsonb 数组中的对象取消嵌套到单独的行中

从输出中删除 jsonb_build_object

如何 for each id创建长度等于id长度的不同日期序列?

如何使用SELECT语句进行左连接,并根据右表中的特定值过滤结果?

如何为给定的股票数据集计算利润/亏损,确保先卖出先买入的股票

避免在SQL中使用具有相同条件的多个子查询

在Snowflake中如何使用SQL对版本字符串进行排序?

oracle中多行的跨日期范围的交集

如何在 DAX 中通过 Window 函数应用订单

面对来自以下两个代码的不同输出

PostgreSQL 中的递归树查询