关于COM+提交数据时的事务问题。分不够可再开贴。
做三层开了时遇到一个问题
做了两个COM+组件
A组件中有以下一段代码 ,事务为支持
procedure Tran(var ID,BookID: WideString);
begin
if (GetObjectContext.IsTransaction=True) then ShowMessage('Transaction Star!')
else ShowMessage('Transaction Not Star!');
try
//update A表
with AdoQuery1 do
begin
close;
sql.clear;
sql.add('update Person set BookID=BookID where ID=:ID');
Parameters.ParamByName('ID').values=ID;
Parameters.ParamByName('BookID').values:=BookID;
execsql;
end;
//update B表
with AdoQuery2 do
begin
close;
sql.clear;
sql.add('update Book set ID=ID where BookID=:BookID');
Parameters.ParamByName('ID').values=ID;
Parameters.ParamByName('BookID').values:=BookID;
execsql;
end;
setComplete;
except
on Exection do
SetAbort
end;
end;
B组件代码如下,事务为需要
procedure Updaet(var ID,BookID: WideString);
var
UpdateCom: imtsUpdate;
begin
updatecom:=comtsupdate.create;
updatecom.tran(ID,BookID);
end;
运行程序后,人为的给A表制造一点错误,让A表不能更新,然后执行更新操作,弹出对话框显示事务开始了,结果是A表数据没能更新,B表数据被更新了。为什么事务不能起到保护作用?
SQL Server的MSDTC也启动了的。