TransactionOptions transactionOption = new TransactionOptions();
//设置事务隔离级别
transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
// 设置事务超时时间为60秒
transactionOption.Timeout = new TimeSpan(0, 0, 60);
using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, transactionOption))
{
try
{
//在这里实现事务性工作
// 没有错误,提交事务
scope.Complete();
}
catch (Exception ex)
{
throw new Exception("保存操作异常,原因:" + ex.Message);
}
finally
{
//释放资源
scope.Dispose();
}
}
return "";