c# - 代码保持超时

标签 c# sql-server-2008 asp.net-4.0

所以,我们得到了这组代码,由于某种原因,它一直在超时。它运行的不是存储过程,因为它运行良好。此外,如果我们从 C# 代码中删除参数,代码就会运行。参数不断中断(导致它超时),我们无法弄清楚原因。

c#:

public static PTWViewList GetList(int studynumber) 
        {
            PTWViewList tempList = new PTWViewList();
            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.cnARDB))
            {
                string spName = "ardb.PTWViewSelect";
                SqlCommand myCommand = new SqlCommand(spName, myConnection);
                myCommand.CommandType = CommandType.StoredProcedure;
                myCommand.Parameters.AddWithValue("@study", studynumber); 

                myConnection.Open();
                using (NullableDataReader myReader = new NullableDataReader(myCommand.ExecuteReader())) /*this is where the code times out*/
                {
                    tempList = new PTWViewList();
                    while (myReader.Read())
                    {
                        tempList.Add(FillDataRecord(myReader));
                    }
                    myReader.Close();
                }
            }

            tempList.ListCount = tempList.Count;
            return tempList;
        }

存储过程:

CREATE PROCEDURE [ardb].[PTWViewSelect] 
    @studynumber int = NULL,
    @quoteid uniqueidentifier = NULL,
    @lineitemid uniqueidentifier = NULL
AS
BEGIN
    SET NOCOUNT ON;

    SELECT
        [Study]
        ,[LineItemID]
        ,[QuoteID]
        ,[Total]
        ,[COOP]
        ,[VendorCost]
        ,[CustCost]
        ,[LineItemNumber]
        ,[StudyTypeCode]
        ,[GroupLeader]
        ,[PTWDate]
        ,[PONumber]
        ,[POStatus]
        ,[StudyDirector]
        ,[SL_DESC_L]
        ,[SL_Code]
        ,ProjectDescription
        ,CreatedBy
        ,chARProcess
        ,CODate
    FROM
        [ARDB].[dbo].[PTWView]
    WHERE
        (@studynumber is null or StudyNumber=@studynumber)
        AND (@quoteid is null or QuoteID=@quoteid)
        AND (@lineitemid is null or LineItemID = @lineitemid)
END

最佳答案

你试过吗

myCommand.Parameters.AddWithValue("@studynumber", studynumber);

代替:

myCommand.Parameters.AddWithValue("@study", studynumber); 

关于c# - 代码保持超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4539765/

相关文章:

sql检查2列中的逻辑错误

sql-server - %% 与 CONTAINSTABLE

web-config - ASP.NET-4 IIS7.5 web.config serverRuntime 元素

c#线程化嵌套循环函数,每次执行有两个单独的作业

c# - 如何将 mongo ObjectID 存储到 SQL Server 中?

c# - 在 C# 中获取 unicode 目录名称?

SQL Server代理作业帐户问题

asp.net - 通过 clientID 改变用户控件上的输出缓存

c# - ASP.Net 4.0 - 站点地图构建中需要响应吗?

c# - 在 C# 中使用 DateTime 和 TimeSpan 进行计算