V
virtualmfc
Unregistered / Unconfirmed
GUEST, unregistred user!
我最近写的一个项目中,使用的是COM+,按照COM+规范的要求,我写了一个协同事务的方法,但在执行时却发现SQL Server 2000会报灾难性故障。下面是摘取出来的代码:
//TGoodsFacade是Require Transaction的COM+对象
procedure TGoodsFacade.DelGoods(GoodsID: Integer;
Value: OleVariant);
var
LOnHand: IOnHand;
LGoods: IGoods;
begin
ObjectContext.CreateInstance(CLASS_Goods, IID_IGoods, LGoods);
ObjectContext.CreateInstance(CLASS_OnHand, IID_IOnHand, LOnHand);
LOnHand.DelOnHand(GoodsID);
//库存表的DelOnHand方法
LGoods.Save(Value);
//调用货品表的Save
end;
//库存表的DelOnHand方法(Support Transaction COM+)
procedure TOnHand.DelOnHand(GoodsID: Integer);
var
LCommandText: String;
RecordsAffected: Integer;
begin
try
LCommandText := Format('DELETE FROM OnHand WHERE GoodsID=%d',[GoodsID]);
Conn.Execute(LCommandText, RecordsAffected);
SetComplete;
except
SetAbort;
raise;
end;
end;
//货品表的Save方法(Support Transaction COM+)
procedure TGoods.Save(Value: OleVariant);
begin
try
with DataSetdo
begin
Close;
CommandText := 'SELECT * FROM Goods WHERE 1=0';
Open;
end;
ClientDataSet.Data := Value;
if ClientDataSet.ApplyUpdates(0) > 0 then
raise Exception.Create('更新货品表错误,请与管理员联系!');
SetComplete;
except
SetAbort;
raise;
end;
end;
//TGoodsFacade是Require Transaction的COM+对象
procedure TGoodsFacade.DelGoods(GoodsID: Integer;
Value: OleVariant);
var
LOnHand: IOnHand;
LGoods: IGoods;
begin
ObjectContext.CreateInstance(CLASS_Goods, IID_IGoods, LGoods);
ObjectContext.CreateInstance(CLASS_OnHand, IID_IOnHand, LOnHand);
LOnHand.DelOnHand(GoodsID);
//库存表的DelOnHand方法
LGoods.Save(Value);
//调用货品表的Save
end;
//库存表的DelOnHand方法(Support Transaction COM+)
procedure TOnHand.DelOnHand(GoodsID: Integer);
var
LCommandText: String;
RecordsAffected: Integer;
begin
try
LCommandText := Format('DELETE FROM OnHand WHERE GoodsID=%d',[GoodsID]);
Conn.Execute(LCommandText, RecordsAffected);
SetComplete;
except
SetAbort;
raise;
end;
end;
//货品表的Save方法(Support Transaction COM+)
procedure TGoods.Save(Value: OleVariant);
begin
try
with DataSetdo
begin
Close;
CommandText := 'SELECT * FROM Goods WHERE 1=0';
Open;
end;
ClientDataSet.Data := Value;
if ClientDataSet.ApplyUpdates(0) > 0 then
raise Exception.Create('更新货品表错误,请与管理员联系!');
SetComplete;
except
SetAbort;
raise;
end;
end;