TransactionScope使用

public void FixProjectSorceInsert()
{
TransactionOptions transactionOption = new TransactionOptions();
//设置事务隔离级别
transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
// 设置事务超时时间为120秒
transactionOption.Timeout = new TimeSpan(0, 0, 120);

using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transactionOption))
{
try
{
Insert();

Update();

Delete();

// 没有错误,提交事务
scope.Complete();
}
catch (Exception ex)
{
throw new Exception("发送信息异常,原因:" + ex.Message);
}
finally
{
//释放资源
scope.Dispose();
}

}
}

上一篇:6个原因说服你选择PostgreSQL9.6


下一篇:牛客寒假算法基础集训营3B 处女座的比赛资格(用拓扑排序解决DAG中的最短路)