Two phase commit with IBDAC and Firebird

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
dennis
Posts: 10
Joined: Tue 23 Oct 2007 14:10

Two phase commit with IBDAC and Firebird

Post by dennis » Thu 23 Dec 2010 16:00

Can anyone provide guidance or an example of using IBDAC components to perform a two-phase commit involving two Firebird databases?

Thanks,

Dennis

AndreyZ

Post by AndreyZ » Mon 27 Dec 2010 16:11

Hello,

You can try using this code:

Code: Select all

  IBCQuery1.AutoCommit := false;
  IBCQuery1.Connection := IBCConnection1; // connection to the first database
  IBCQuery1.UpdateTransaction := IBCTransaction; // one transaction for both databases
  IBCQuery1.Open;
  IBCQuery2.AutoCommit := false;
  IBCQuery2.Connection := IBCConnection2; // connection to the second database
  IBCQuery2.UpdateTransaction := IBCTransaction;
  IBCQuery2.Open;
  IBCTransaction.AddConnection(IBCConnection1);
  IBCTransaction.AddConnection(IBCConnection2);
  IBCTransaction.StartTransaction;
  try
    IBCQuery1.Edit;
    IBCQuery1.FieldByName('test1').AsString := 'test1';
    IBCQuery1.Post;
    IBCQuery2.Edit;
    IBCQuery2.FieldByName('test2').AsString := 'test2';
    IBCQuery2.Post;
    IBCTransaction.Commit;
  except
    IBCTransaction.Rollback;
  end;

Post Reply