2012-04-23 47 views
0

我在SQL存儲過程中存在間歇性問題,它從SQL dB中檢索產品。我們有大約3500名活躍用戶,並且通常使用該程序一次約有15-30名用戶登錄。在過去的一週中,我一直收到超時過期的消息,如下所示:SQL超時期間已逝 - 間歇性問題

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)在系統上.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior,SqlCommand cmdHandler,SqlDataReader dataStream,BulkCopySimpleResultSet bulkCopyHandler,TdsParserStateObject stateObj)System.Data.SqlClient.SqlDataReader.ConsumeMetaData()System.Data.SqlClient.SqlDataReader.get_MetaData()在系統上.Data.SqlCommand.FinishExecuteReader(SqlDataReader ds,RunBehavior runBehavior,String resetOptionsString)在System.Data.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior,RunBehavior runBehavior,布爾returnStream,布爾異步)在System.Data.SqlClient.SqlCommand。 RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String meth odm,DbAsyncResult result)在System.Data.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior,RunBehavior runBehavior,Boolean returnStream,String method)System.Data.System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior行爲,字符串方法)上。 SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior行爲)在System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior行爲)在System.Data.Common.DbDataAdapter.FillInternal(DataSet數據集,DataTable []數據表,Int32 startRecord ,Int32 maxRecords,String srcTable,IDbCommand命令,CommandBehavior行爲)在System.Data.Common.DbDataAdapter(DataSet數據集,Int32 startRecord,Int32 maxRecords,字符串srcTable,IDbCommand命令,CommandBehavior行爲) .Fill(DataSet dataSet,String srcTable)at clearance.PopulateRegularLineList(Int32 PageIndex)in e:\ Websites \

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 

任何想法?提前致謝。

回答

0

你有關聯的代碼嗎?有多少個併發連接,你確定連接在執行完成後關閉了嗎?

+0

你好,我已經將SQL代碼添加到原始問題。謝謝 – odinel 2012-04-24 07:44:35