Specifying Whether the Connection Automatically Initiates Transactions
Go Up to Fine-tuning a Connection
Use the Attributes property to control the connection component's use of retaining commits and retaining aborts. When the connection component uses retaining commits, then every time your application commits a transaction, a new transaction is automatically started. When the connection component uses retaining aborts, then every time your application rolls back a transaction, a new transaction is automatically started.
Attributes is a set that can contain one, both, or neither of the constants xaCommitRetaining and xaAbortRetaining. When Attributes contains xaCommitRetaining, the connection uses retaining commits. When Attributes contains xaAbortRetaining, it uses retaining aborts.
Check whether either retaining commits or retaining aborts is enabled using the in operator. Enable retaining commits or aborts by adding the appropriate value to the attributes property; disable them by subtracting the value. The example routines below respectively enable and disable retaining commits in an ADO connection component.
procedure TForm1.RetainingCommitsOnButtonClick(Sender: TObject); begin with ADOConnection1 do begin Close; if not (xaCommitRetaining in Attributes) then Attributes := (Attributes + [xaCommitRetaining]) Open; end; end; procedure TForm1.RetainingCommitsOffButtonClick(Sender: TObject); begin with ADOConnection1 do begin Close; if (xaCommitRetaining in Attributes) then Attributes := (Attributes - [xaCommitRetaining]); Open; end; end;
void __fastcall TForm1::RetainingCommitsOnButtonClick(TObject *Sender) { ADOConnection1->Close() if (!ADOConnection1->Attributes.Contains(xaCommitRetaining)) ADOConnection1->Attributes = TXactAttributes() << xaCommitRetaining; ADOConnection1->Open() } void __fastcall TForm1::RetainingCommitsOffButtonClick(TObject *Sender) { ADOConnection1->Close() if (ADOConnection1->Attributes.Contains(xaCommitRetaining)) ADOConnection1->Attributes = TXactAttributes() >> xaCommitRetaining; ADOConnection1->Open() }