这是在一个事务中修改表的代码。据我所知,为什么 IsolationLevel Serializable 读取没有被阻止,但我无法从表中选择记录。如何在不阻止从表中选择的情况下运行事务?
TransactionOptions opt = new TransactionOptions();
opt.IsolationLevel = IsolationLevel.Serializable;
using (TransactionScope scope = new TransactionScope(
TransactionScopeOption.Required, opt))
{
// inserts record into table
myObj.MyAction();
// trying to select the table from Management Studio
myObj2.MyAction();
scope.Complete();
}
最佳答案
看看http://msdn.microsoft.com/en-us/library/ms173763.aspx有关 SQL Server 中隔离级别的说明。 SERIALIZABLE 提供最高级别的隔离,并在事务完成之前对表进行范围锁定。您必须使用较低的隔离级别才能在事务期间允许并发读取。
关于c# - 允许在事务运行时选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6689133/