C# 尝试运行存储过程时ADO.NET超时

C# 尝试运行存储过程时ADO.NET超时,c#,asp.net,sql-server-2008,ado.net,C#,Asp.net,Sql Server 2008,Ado.net,下面是一段错误的代码: string storedProcedure = "sp3111Commissions"; using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand()) { string ConnectionString = CMSLayers.DataLayer.Universal.GetConnectionString(); Connectio

下面是一段错误的代码:

    string storedProcedure = "sp3111Commissions";
    using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand()) {
    string ConnectionString = CMSLayers.DataLayer.Universal.GetConnectionString();
    ConnectionString = 
    using (System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection()) {
    //Response.Write(EndDate2.ToString());
    //Response.End();
            conn.ConnectionString = ConnectionString;
    //Response.Write(ConnectionString); Response.End(); return null;
    cmd.CommandType = System.Data.CommandType.StoredProcedure;
    cmd.Connection = conn;
    cmd.CommandText = storedProcedure;
    cmd.Parameters.Add("@ShopID", System.Data.SqlDbType.Int);
    cmd.Parameters["@ShopID"].Value = ShopID;
    cmd.Parameters.Add("@StartDate", System.Data.SqlDbType.DateTime);
    cmd.Parameters["@StartDate"].Value = StartDate;
    cmd.Parameters.Add("@EndDate", System.Data.SqlDbType.DateTime);
    cmd.Parameters["@EndDate"].Value = EndDate;
    cmd.Parameters.Add("@StartDate2", System.Data.SqlDbType.DateTime);
    cmd.Parameters["@StartDate2"].Value = StartDate2;
    cmd.Parameters.Add("@EndDate2", System.Data.SqlDbType.DateTime);
    cmd.Parameters["@EndDate2"].Value = EndDate2;
    cmd.CommandTimeout = 1380;

    try
    {
        System.Data.DataSet ds;
        using (System.Data.SqlClient.SqlDataAdapter da= new System.Data.SqlClient.SqlDataAdapter()) {
        System.Data.DataTable Table = null;

        conn.Open();

        da.SelectCommand = cmd;

        using (ds = new System.Data.DataSet()) {

        da.Fill(ds);

        if (ds.Tables.Count > 0)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                Table = ds.Tables[0];
            }
        }
        conn.Close();
        return Table;
        }
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }       
    }
    }
发生的情况是它挂起约2分钟,然后最终出现超时错误。但是,如果我在SQLServerManagementStudio中使用相同的参数运行存储过程,数据会立即返回


“挂起”出现在“da.Fill(ds);”行。有人有什么想法吗?这是.NET2.0,顺便问一下,可能有重复的问题吗


在您的
SELECT
语句中,考虑使用(NOLOCK)。

存储过程中包含什么?您是否尝试过用一些您知道会很快处理的琐碎内容替换存储过程?如果这有帮助,您就知道这是存储过程。如果没有帮助,你知道这是你的客户端代码。你能包括连接字符串(当然没有任何密码和其他敏感数据)吗?@marc_s-它很复杂,如果你愿意,我可以发布它。但是请记住,从Studio Manager中运行存储过程几乎会立即产生结果。这让我相信问题不在存储过程中;数据库=;UID=sa;密码=mypwd;有趣。让我将NOLOCK添加到连接中,看看这个解决方案是否适合我。