0

我有一个来自生产系统的奇怪问题。我已经用 no_lock 的读操作和在同一范围内的表锁的写操作定义了 readCommitted 事务。

但是,多个进程能够覆盖锁并能够执行影响很大的写操作。请帮忙!。谢谢。

using (TransactionScope transaction = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions() { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted }))
{
    dataAccess.ExecNonQuery("GetNextOrder", parametersList); //read orders from table 1, there is NO_lock in the SP

    orderIDParameter = (IParameter)parametersList[0];
    int orderIDParameterValue = (int) orderIDParameter.Value;

    if (orderIDParameterValue != NullOrderID)
    {
       parametersList.Clear();
       IParameter orderIDLockParameter = SQLClientFactory.GetParameter("@OrderID", orderIDParameterValue, Direction.In);
       IParameter lockNameParameter = SQLClientFactory.GetParameter("@LockName", lockName, Direction.In);
       parametersList.Add(orderIDLockParameter);
       parametersList.Add(lockNameParameter);

       dataAccess.ExecNonQuery("Insert_SP", parametersList);  //Insert into table 2

       orderID = orderIDParameterValue;
    }

    transaction.Complete();
}

存储过程:GetNextOrder

SELECT top 1 @OrderID=ht.OrderID        
     FROM dbo.table1 ht WITH(nolock)       
     left join dbo.table2 htl WITH(nolock) on ht.orderid = htl.orderid        
     WHERE ht.Status in (0,1) 

存储过程:Insert_SP

CREATE procedure [dbo].[Insert_SP] (
@OrderID INT,
@LockName VARCHAR(50)
   )
AS
BEGIN
SET NOCOUNT ON

 insert into table2 (OrderID, LockName) VALUES (@OrderID, @LockName) 

SET NOCOUNT OFF
END
4

1 回答 1

0

您的 dataAccess 类是如何定义的?

我怀疑它没有参与新交易 - 使用

connection.EnlistTransaction(Transaction.Current) 

在那个班级。

于 2012-09-13T12:37:28.083 回答