开启事物时ADOConnection.begin Trans是应该写在try前面还是后面?(100分)

  • 主题发起人 主题发起人 sunnyfairy
  • 开始时间 开始时间
S

sunnyfairy

Unregistered / Unconfirmed
GUEST, unregistred user!
开启事物时ADOConnection.BeginTrans是应该写在try前面还是后面?<br>一直搞不清楚这个问题.应该有区别吧.
 
都可以,基本上没有区别
 
中间的语句执行是否成功,跟try没多大关系,可能语句没执行成功,但except不会触发,当然,如果网络可能突然中断,那么BeginTrans可能也会出错,考虑到这一层,你就把它写在try后面吧,否则的话,你原意可能是想放在前面,也没多大关系[:D]
 
习惯上-- &nbsp;[:)]<br>基本的数据异常回滚块:<br>&nbsp; ADOConnection.BeginTrans;<br>&nbsp; try<br>&nbsp; &nbsp; &nbsp;...<br>&nbsp; &nbsp; &nbsp;ADOConnection.CommitTrans;<br>&nbsp; except<br>&nbsp; &nbsp; &nbsp;ADOConnection.RollbackTrans;<br>&nbsp; end;<br><br>应用异常保护块:<br>&nbsp; try<br>&nbsp; &nbsp; &nbsp;ADOConnection.BeginTrans;<br>&nbsp; &nbsp; &nbsp;try<br>&nbsp; &nbsp; &nbsp; &nbsp;...<br>&nbsp; &nbsp; &nbsp; &nbsp;ADOConnection.CommitTrans;<br>&nbsp; &nbsp; &nbsp;except<br>&nbsp; &nbsp; &nbsp; &nbsp;ADOConnection.RollbackTrans;<br>&nbsp; &nbsp; &nbsp;end;<br>&nbsp; except<br>&nbsp; &nbsp; ...<br>&nbsp; finally<br>&nbsp; &nbsp; ...<br>&nbsp; end;
 
个人习惯:<br>&nbsp; try<br>&nbsp; &nbsp; &nbsp;ADOConnection.BeginTrans;<br>&nbsp; &nbsp; &nbsp; &nbsp;...<br>&nbsp; &nbsp; &nbsp;ADOConnection.CommitTrans;<br>&nbsp; except<br>&nbsp; &nbsp; &nbsp;ADOConnection.RollbackTrans;<br>&nbsp; end;
 
个人觉得放在前面比较好些.
 
一般都放在前面,我都是这样的习惯
 
后退
顶部