所以,我们得到了这组代码,由于某种原因,它一直在超时。它运行的不是存储过程,因为它运行良好。此外,如果我们从 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/