我在SQL Server中有一个基本的SELECT存储过程,它连接到MS Access前端。当多个用户尝试运行相同的存储过程时(例如ODBC-调用失败或表当前被锁定),用户将收到表锁定。有没有办法实现队列或防止这种情况发生。
我尝试将服务器移近一些,以查看是否是延迟问题,并尝试使用OPTION(MAXDOP 1)以防出现处理器问题。
(@username as varchar(20),
@searchcriteria as varchar(50)
)
AS
SET NOCOUNT ON;
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
--SET @username = 'caddo';
--SET @searchcriteria = 9;
--SET @portfolio = 'WH – Apollo';
--PRINT '%'+ RIGHT(CAST(@situsloanid as varchar(10)),@loanLength) + '%'
SELECT tblPortfolio.PortfolioID,
tblAssets.AssetID,
tblAssets.ModelEntity,
tblPortfolio.Portfolio,
tblAssets.SitusLoanID,
tblEmployees.Last AS AMIntials,
tblEmployees_1.Last AS TeamLead,
tblStatus.StatusType, tblEmployees.NetworkUserName, tblRegion.ID, tblRegion.Region,
IIf(1=1 Or 0=1,1,IIf(@username=[tblEmployees].[NetworkUserName] Or @username=[tblEmployees_1].[NetworkUserName] Or @username=[tblEmployees_2].[NetworkUserName] Or @username=[tblEmployees_3].[NetworkUserName] Or @username=[tblEmployees_4].[NetworkUserName] Or @username=[tblEmployees_5].[NetworkUserName],1,0)) AS [Select],
tblEmployees_1.NetworkUserName, tblEmployees_2.Last AS PMLead, tblEmployees_3.Last AS Analyst, tblEmployees_4.Last AS Admin, tblEmployees_5.Last AS ComplianceLead, tblAssets.AssetName,
tblAssets.BorrowerName, tblEmployees.compliance AS ComplianceBool, tblAssets.SitusLoanID, tblAssets.Alias
FROM tblAssets LEFT JOIN tblEmployees AS tblEmployees_5 ON tblAssets.ComplianceID = tblEmployees_5.LoginID
LEFT JOIN tblEmployees AS tblEmployees_3 ON tblAssets.AnalystID = tblEmployees_3.LoginID
LEFT JOIN tblEmployees AS tblEmployees_2 ON tblAssets.PMLeaderID = tblEmployees_2.LoginID
LEFT JOIN tblEmployees AS tblEmployees_1 ON tblAssets.AMLeaderID = tblEmployees_1.LoginID
LEFT JOIN tblEmployees ON tblAssets.AssetMngrID = tblEmployees.LoginID
LEFT JOIN tblStatus ON tblAssets.PipelineStatusID = tblStatus.StatusID
LEFT JOIN tblEmployees AS tblEmployees_4 ON tblAssets.ServicerContactID = tblEmployees_4.LoginID
LEFT JOIN tblPortfolio ON tblAssets.PortfolioID = tblPortfolio.PortfolioID
LEFT JOIN tblRegion ON tblAssets.RegionId = tblRegion.ID
WHERE (1=1 )
AND (tblPortfolio.Portfolio Like '%'+ @searchcriteria + '%'
OR tblAssets.SitusLoanID Like '%'+ @searchcriteria + '%'
OR tblAssets.BorrowerName Like '%'+ @searchcriteria + '%'
OR tblEmployees_2.Last Like '%'+ @searchcriteria + '%'
OR tblAssets.AssetName Like '%'+ @searchcriteria + '%'
OR tblAssets.Alias Like '%'+ @searchcriteria + '%'
AND (IIf(1=1 Or 0=1,1,IIf(@username=[tblEmployees].[NetworkUserName]
Or @username=[tblEmployees_1].[NetworkUserName]
Or @username=[tblEmployees_2].[NetworkUserName]
Or @username=[tblEmployees_3].[NetworkUserName]
Or @username=[tblEmployees_4].[NetworkUserName]
Or @username=[tblEmployees_5].[NetworkUserName],1,0)))=1)
ORDER BY tblAssets.AssetName, tblAssets.SitusLoanID
OPTION (MAXDOP 1);
我希望用户能够运行SP并接收到锁错误,或者希望他们被放置在队列中以接收期望的数据。