首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > PB >

同时向不同的表中写数据,提交失败后,数据库事务不回滚!解决思路

2012-03-27 
同时向不同的表中写数据,提交失败后,数据库事务不回滚!!!!!代码如下:string ls_temp_string1,ls_temp_stri

同时向不同的表中写数据,提交失败后,数据库事务不回滚!!!!!
代码如下:

  string ls_temp_string1,ls_temp_string2

ls_temp_string1="a"
 
ls_temp_string2="b"

//a数据插入
INSERT INTO T_a(……)
USING at_Trans;

  if at_Trans.SqlCode = 0 then 
//b数据插入
INSERT INTO T_b(……)
USING at_Trans;

if at_Trans.SqlCode = 0 then 
//c数据插入
INSERT INTO T_c(……)
USING at_Trans;
  COMMIT USING at_Trans;
 
if at_Trans.SqlCode = 0 then
return STATE_OK
else
  //c数据插入失败
ROLLBACK USING at_Trans; 
gf_wtkj_log(ls_temp_string1)
openwithparm(w_message_error,"数据库故障3")
return STATE_ERROR
end if
else
//b数据插入失败
ROLLBACK USING at_Trans; 
gf_wtkj_log(ls_temp_string1+ls_temp_string2)
openwithparm(w_message_error,"数据库故障2")
return STATE_ERROR
end if
else
//a数据插入失败
gf_wtkj_log(ls_temp_string1)
openwithparm(w_message_error,"数据库故障1")
return STATE_ERROR
  end if

[解决办法]
USING at_Trans; 
COMMIT USING at_Trans;
  
if at_Trans.SqlCode = 0 then
return STATE_OK

I 服了 you .已经提交过了然后判断sqlcode再回滚 看的我两眼一黑....
[解决办法]
楼主不会提问吧·格式都没整·

C# code
string ls_temp_string1,ls_temp_string2ls_temp_string1="a"  ls_temp_string2="b"//a数据插入INSERT INTO T_a(……)USING at_Trans;if at_Trans.SqlCode = 0 then      //b数据插入    INSERT INTO T_b(……)    USING at_Trans;    if at_Trans.SqlCode = 0 then          //c数据插入        INSERT INTO T_c(……)        USING at_Trans;         COMMIT USING at_Trans;          if at_Trans.SqlCode = 0 then            return STATE_OK        else            //c数据插入失败            ROLLBACK USING at_Trans;              gf_wtkj_log(ls_temp_string1)            openwithparm(w_message_error,"数据库故障3")            return STATE_ERROR        end if    else        //b数据插入失败        ROLLBACK USING at_Trans;          gf_wtkj_log(ls_temp_string1+ls_temp_string2)        openwithparm(w_message_error,"数据库故障2")        return STATE_ERROR    end if else    //a数据插入失败    gf_wtkj_log(ls_temp_string1)    openwithparm(w_message_error,"数据库故障1")    return STATE_ERRORend if
[解决办法]
楼上正解
[解决办法]
格式一理,问题自然就看出来了·

光这一句:
//a数据插入
INSERT INTO T_a(……)
USING at_Trans;

如果不成功,你都没有回滚·

另外,看看你的autocommit是否设置为false
[解决办法]
C# code
可以这样写,更清晰和捕捉错误些·string ls_temp_string1,ls_temp_string2ls_temp_string1="a"  ls_temp_string2="b"//a数据插入INSERT INTO T_a(……)USING at_Trans;if sqlca.sqlcode <> 0 then    //a数据插入失败    ROLLBACK USING at_Trans;     gf_wtkj_log(ls_temp_string1)    openwithparm(w_message_error,"数据库故障1")    return STATE_ERRORend if//b数据插入INSERT INTO T_b(……)USING at_Trans;if sqlca.sqlcode <> 0 then    //b数据插入失败    ROLLBACK USING at_Trans;      gf_wtkj_log(ls_temp_string1+ls_temp_string2)    openwithparm(w_message_error,"数据库故障2")    return STATE_ERRORend if//c数据插入INSERT INTO T_c(……)USING at_Trans;  //c数据插入失败if sqlca.sqlcode <> 0 then    ROLLBACK USING at_Trans;      gf_wtkj_log(ls_temp_string1)    openwithparm(w_message_error,"数据库故障3")    return STATE_ERRORend ifcommit using at_Trans; 


[解决办法]
你中间有个commit了呀
[解决办法]
请先确定 at_Trans.autocommit = false

热点排行