[英]Transaction Scope Locks table
I am using C# 3.5 and I have a code within transaction scope that is locking the tables , how can I prevent the transaction scope from locking these tables ? 我正在使用C#3.5,并且在事务范围内有一个锁定表的代码,如何防止事务范围锁定这些表?
Thanks, 谢谢,
Add a TransactionScope
with the option RequireNew
and set the IsolationLevel
to ReadUncommitted
: 添加
TransactionScope
的选项RequireNew
和设置IsolationLevel
到ReadUncommitted
:
using (var t = new TransactionScope(TransactionScopeOption.RequireNew,
new TransactionOptions {
IsolationLevel = IsolationLevel.ReadUncommitted
}))
{
// your code
}
The TransactionScope
makes the code block transactional. TransactionScope
使代码块具有事务性。 The inwolved tables are locked while "code" has not been COMMITED/ROLLED BACK
. 当“代码”尚未
COMMITED/ROLLED BACK
被锁定的表将被锁定。
您应该使用关键字来防止表锁定,例如nolock,但是要注意如何读取它们,例如读取已提交或未提交读,因为这可能会使您陷入所谓的脏读。
I solved this by adding 我通过添加解决了这个问题
with(nolock)
to the SQL stored procedures that are involved in the transaction. 事务中涉及的SQL存储过程。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.