同时写两个数据库的问题

这篇博客探讨了在处理数据库操作时遇到的问题,特别是在执行事务过程中,如果在循环中出现错误,导致无法进行回滚或确认写入的情况。博主提出了在多步骤数据库操作中,如何确保数据一致性的问题,并寻求解决方案。
sub CancelCheckArticle(ID)  '取消检验并在工资表中删除记录
set rs=server.createobject("adodb.recordset")
sql="select C_LSH, from WAGE where C_LSH=" & CLng(ID)
rsDel.open sqlDel,conn,1,3
if rsDel.bof and rsDel.eof then
response.write "找不到相关记录"
rs.Close
set rs=nothing
response.end
else
sqlDel="select C_LSH,C_YSM,C_YSSJM,C_GM,C_YQ from PRODUCTS where C_LSH=" & CLng(ID)
Set rsDel= Server.CreateObject("ADODB.Recordset")
rsDel.open sqlDel,conn,1,3
if rsDel.bof and rsDel.eof then
response.write "找不到相关记录"
elseif not isNull(rsDel("C_GM")) or not isNull(rsDel("C_YQ")) then 
response.write ""&CLng(ID)&" 已经有刮磨或油漆的记录,不能取消!"
rsDel.close
set rsDel=nothing
call CloseConn()
response.end
elseif (Year(Date) &"/"& Month(Date))<>(year(rsDel("C_YSSJM"))&"/"&month(rsDel("C_YSSJM"))) then   '只有当月才能取消审核
rsDel.close
set rsDel=nothing
call CloseConn()
response.end
else
rsDel("C_YSM")=null
rsDel("C_YSSJM")=null
end if
rsDel.update
'删除工资表中的记录
sql2="delete from WAGE where C_LSH="&CLng(ID)
conn.execute sql2
rsDel.close
set rsDel=nothing
end if
end sub


if submit<>"删除" and xuanze="Check" then
conn.begintrans  '开启事务
if instr(C_LSH,",")>0 then
    idArr=split(C_LSH)
for i = 0 to ubound(idArr)
call CheckArticle(idarr(i))
next
else
call CheckArticle(clng(C_LSH))
end if
if err <> 0 then  '如果错误则数据库回滚
conn.rollbacktrans 
err.clear
response.write "<center><font color=red>"
response.Write "添加失败!<br>"
response.write "</font></center>"
else 
conn.committrans '正确则写入
Response.Write "添加记录成功!"
call CloseConn()
response.write  " <script language=javascript>alert('流水号"&C_LSH&"检验成功');location.href='check.asp'; </script>" 
end if


如果在循环中有一步是错误的,那么就无法执行conn.rollbacktrans和conn.committrans 这样的话,那些在数据库中临时写入和删掉除的数据怎么办?没有回滚也没有确认写入。这样会不会对后来的调用产生音响?

请赐教!
谢谢
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值