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

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

  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_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

------解决方案--------------------
楼上正解
------解决方案--------------------
格式一理,问题自然就看出来了·

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

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

另外,看看你的autocommit是否设置为false
------解决方案--------------------
C# code
可以这样写,更清晰和捕捉错误些·
string ls_temp_string1,ls_temp_string2

ls_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_ERROR
end 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_ERROR
end 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_ERROR
end if

commit using at_Trans;