这个事务一直成功提交,我第二个删除操作失败返回为0也不回滚,把scope.Complete()代码删除了,也照样成功提交事务。
为什么不回滚? 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))
{
result = channel.Route_DeletebyRoadId(id);
if (result > 0)
{
result = channel.Roadbook_Deletebyid(id);
if (result > 0)
{
scope.Complete();
}
}
}
为什么不回滚? 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))
{
result = channel.Route_DeletebyRoadId(id);
if (result > 0)
{
result = channel.Roadbook_Deletebyid(id);
if (result > 0)
{
scope.Complete();
}
}
}
解决方案 »
- 请问有人做过用HttpWebRequest通过"Post"方法,对https地址提交请求的吗?
- 文字与图片如何转成二进制
- 每个展位的公司的图片都是这样动态变化的
- 比如现在有字符串 "20081225"加上六个月后值。要怎么求。在线等
- 数据库中“导航”一词是什么含义?
- 急!急!急!急!急!急!!!!(在线等,马上接分!!!)
- 连接 数据库 不上——求搭救
- 就90分了 全散 5个问题 精通WinForm的都进来拿分
- 在c#开发的网站中,网站banner需要根据登陆者的所在的地区,显示不同的文字,banner是flash做的
- 关于ProcessBar进度条的使用!请高手帮忙!
- ADO.net 数据库连接并插入数据。是杨中科老师的视频,请高手帮忙!
- 万年历的设计
http://topic.csdn.net/u/20080111/16/8574ee34-dd7d-4748-a2e1-a1939d6b93e7.html
此外,你的这些貌似进行了分层处理
result = channel.Route_DeletebyRoadId(id);
result = channel.Roadbook_Deletebyid(id);
为什么这些数据处理的事务性的东西不放在数据访问部分呢
//设置事务隔离级别
transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
// 设置事务超时时间为60秒
transactionOption.Timeout = new TimeSpan(0, 0, 60); using (TransactionScope scope = new TransactionScope (TransactionScopeOption.Required, transactionOption))
{
result = channel.Route_DeletebyRoadId(id);
if (result > 0)
{
result = channel.Roadbook_Deletebyid(id);
if (result > 0)
{
scope.Complete();
}
else
{
scope.Dispose();
}
}
}