摘要:在软件开发和数据库操作中,经常出现需要共同进退的情况,要么一起成功,要么一起失败。
此时推荐使用分布式事务来解决这类问题。
//包起来就会两者一起。一起成功,或者一起失败
using(TransactionScope ts=new TransactionScope())
{
"update Account set Amount=Amount-3000 where name='a'";//从A账户扣钱的操作
"update account set Amount=Amount+3000 where name='b'"//向B账户增加钱的操作
ts.Complete();//忘记这句话,两个都插入失败
}
原文地址:http://blog.csdn.net/fanrong1985/article/details/40782759