1

在 c# 的事务范围中设计了一个选择 sql 查询(例如从 table1 中选择 *)。通常有一个环境事务,但是如果我在执行这个 sql 查询时抑制环境事务,是否有性能提升?

using (TransactionScope scope1 = new TransactionScope())
{
     // here there are some business processes

   using (TransactionScope scope1 = new TransactionScope(TransactionScopeOption.Suppressed)) //Is this suppressed transaction scope useful in terms of performance?
   {

       //Here there is a select sql query with no lock table hint.
   }
}
4

1 回答 1

1

是的-因为 TransactionScope(正如您在示例中使用的那样)使用 Serializable 隔离级别,因此对于不需要保护该隔离级别的某些查询抑制它将防止在数据库服务器上获取读取锁(尤其是如果您使用 READ COMMITTED SNAPSHOT 作为默认隔离级别)。此外,如果您所做的其他事情会将事务提升到 DTC(即,多个连接等),您将节省协调 DTC 的时间,这可能会很慢。

于 2010-01-08T09:20:33.720 回答