SQL超时时间已过去 - 间歇性问题

时间:2012-04-23 15:17:51

标签: sql stored-procedures timeoutexception

我遇到了SQL存储过程的间歇性问题,它从SQL dB中检索产品。我们有大约3500个活跃用户,通常使用该过程一次登录大约15-30个用户。在过去的一周里,我收到了超时过期的消息,如下所示:

  

System.Data.SqlClient.SqlException:超时已过期。操作完成之前经过的超时时间或服务器没有响应。在System.Data.SqlClient.SqlConnection.OnError(SqlException异常,布尔breakConnection)在System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,布尔breakConnection)在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)在系统系统中System.Data.SqlClient.SqlDataReader.get_MetaData()的System.Data.SqlClient.SqlDataReader.ConsumeMetaData()处于.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj) System.Data.SqlClient.SqlCommand的System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,Boolean async)中的.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString)。 RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String meth OD,DbAsyncResult结果)在System.Data.SqlClient.SqlCommand.RunExecuteReader(的CommandBehavior cmdBehavior,RunBehavior runBehavior,布尔returnStream,字符串方法)在System.Data.SqlClient.SqlCommand.ExecuteReader(的CommandBehavior行为,字符串方法)在System.Data。 SqlClient.SqlCommand.ExecuteDbDataReader(的CommandBehavior行为)在System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(的CommandBehavior行为)在System.Data.Common.DbDataAdapter.FillInternal(数据集的数据集,数据表[]数据表,的Int32 startRecord ,的Int32最大记录,字符串srcTable要,IDbCommand的命令,的CommandBehavior行为)在System.Data.Common.DbDataAdapter.Fill(数据集的数据集,的Int32 startRecord,的Int32最大记录,字符串srcTable要,IDbCommand的命令,的CommandBehavior行为)在System.Data.Common.DbDataAdapter在e:\ Websites \

中的clearance.PopulateRegularLineList(Int32 PageIndex)中填充(DataSet dataSet,String srcTable)

SP一次带回12个产品(如果选择了下拉框,则返回更多),并在我手动运行时快速运行。在过去一周内,不同用户在一天中的不同时间发生了20次,因此在运行程序或使用测试帐户浏览网站时,我无法重新创建错误。我已经读过某个地方,添加NOLOCK或增加命令超时可能会修复它,但这只是一个快速掩盖,而不是解决潜在问题(更不用说NOLOCK的数据不佳)。

显示产品的SQL部分位于:

    INSERT INTO @Products (WWHEAD, WWPROD, WWDESC, CTNQTY, PRC1, PRC4, [FILENAME], DPQIS, QTYL, FileReference, LineId, Price5, PriceGroup, Dimensions)                  
(SELECT A.WWHEAD, A.WWPROD, A.WWDESC, A.CTNQTY, 
        CASE WHEN @IsPrice5 = 5 THEN LTRIM(RTRIM(A.Price5)) ELSE LTRIM(RTRIM(A.PRC1)) END,          
        CASE WHEN @IsPrice5 = 5 THEN A.Price5 ELSE A.PRC4 END, 
        [FILENAME],
        (CAST((DPQIS-DPALOC) AS INT)), 
        D.QTY,
        'WebImage',
        LineId,
        CASE WHEN @IsPrice5 = 5 OR A.Price5 = A.PRC4 THEN NULL ELSE A.PRICE5 END,
        LTRIM(RTRIM(PG.PriceCode)) + ' ' + LTRIM(RTRIM(PG.GroupDesc)) + ' ' + LTRIM(RTRIM(PG.DiscDesc)),
        Dimensions
FROM    PRODUCTS A 
        INNER JOIN STOCK C ON A.WWPROD = C.DPPROD AND DPDEPO = 'CH'
        INNER JOIN PROD_COPY W ON A.WWPROD = W.WWPROD 
        INNER JOIN PRODGRP PD ON PD.GPNUM = W.WWPRGP
        LEFT OUTER JOIN ORDERS D ON D.OrderID = @OrdId AND A.WWPROD = D.ProdCode
        LEFT OUTER JOIN PRGRP PG ON  A.WWPCGP = PG.PriceCode
        LEFT OUTER JOIN PRODALT_GRP X ON X.ProdCode = A.WWPROD  
WHERE   A.WWBONS = 'B'
AND     A.WSID = 'WS'
AND     (LTRIM(RTRIM(A.WWHEAD)) = LTRIM(RTRIM(@CatHead)) OR ISNULL(@CatHead, '0') = '0')
AND     (LTRIM(RTRIM(A.WWSBHD)) = LTRIM(RTRIM(@CatSub)) OR ISNULL(@CatSub, '0') = '0')      
AND     (LEFT(LTRIM(RTRIM(A.WWPRGP)), 2) = LTRIM(RTRIM(@BrandT1)) OR ISNULL(@BrandT1, '0') = '0')
AND     (LTRIM(RTRIM(A.GRPTR2)) = LTRIM(RTRIM(@BrandT2)) OR ISNULL(@BrandT2, '0') = '0')
AND     (LTRIM(RTRIM(A.GRPTR3)) = LTRIM(RTRIM(@BrandT3)) OR ISNULL(@BrandT3, '0') = '0')        
AND     X.AltGroupCode = @ProductFilter
AND     A.PRC1 BETWEEN @MinValue AND @MaxValue
AND     A.WWHEAD <> 'B20'   
AND     (A.WWDESC Like ('%' + @SearchString + '%') OR A.WWPROD LIKE ('%' + @SearchString + '%') 
    OR A.WWPROD IN (SELECT Prodcode FROM WDS..Prod_Keywords INNER JOIN WDS..Keywords ON KeyID = KeywordID WHERE Keyword LIKE ('%' + @SearchString + '%')))                          
AND     A.WWBRN NOT IN (SELECT * from WDS.dbo.f_BrandExclusionList(@WebUserName, NULL))
AND     CAST(CASE WHEN NDATMM = '' THEN '01' ELSE NDATMM END + '-' 
            + CASE WHEN NDATDD = '' THEN '01' ELSE NDATDD END + '-' 
            + CASE WHEN NDATYY = '' THEN '1900' ELSE NDATYY END AS DATETIME) BETWEEN @threemonths AND GETDATE()
GROUP BY PD.GPSORT, A.WWHEAD, A.WWPROD, A.WWDESC, A.CTNQTY, A.PRC1, A.PRC4, [FILENAME], C.DPQIS, C.DPALOC, D.QTY, 
        LineId, A.Price5, PG.PriceCode, PG.GroupDesc, PG.DiscDesc, A.WWSBHD, A.WWBRN, 
        A.GRPTR2, A.GRPTR3, A.WWSORT, A.WWPCGP, Dimensions
HAVING  ((A.PRC1 > 20.00 AND ((DPQIS-DPALOC) > 2)) OR (A.PRC1 <= 20.00 AND ((DPQIS-DPALOC) > 8))))
ORDER BY PD.GPSORT, A.WWBRN, A.GRPTR2, A.GRPTR3, A.WWPCGP DESC, A.WWHEAD, A.WWSBHD, A.WWSORT, A.WWPROD  

有什么想法吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

你有相关的代码吗?进行了多少并发连接,确定连接在执行完成后正在关闭?