Can't perform operation on active transaction

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
mariusturnkey
Posts: 5
Joined: Mon 24 Aug 2015 19:04

Can't perform operation on active transaction

Post by mariusturnkey » Tue 17 Jan 2017 08:16

Hi,

I am starting with my porting from FIBPlus to IBDac.

I am getting the following error when executing the following block of code, which is executed when the user hit's the save button on the screen, once he has made changes to the record being displayed.

Code: Select all

procedure TfrmEstimator.btnSaveClick(Sender: TObject);
begin
  qryEstimatorMaintenance.Transaction.StartTransaction;
  try
    qryEstimatorMaintenance.Post;
    qryEstimatorMaintenance.Transaction.Commit;
  except
  on E: Exception do
    begin
      qryEstimatorMaintenance.Transaction.Rollback;
      ShowMessage('Error: ' + E.Message);
    end;
  end;
  Close;
end;


The error occurs on the

Code: Select all

qryEstimatorMaintenance.Transaction.StartTransaction;
line.

I have the following components on the form:
TIBCQuery
TIBCDataSource
TIBCTransaction

When entering the screen the following code is executed to position the record that is being edited.

Code: Select all

procedure TfrmEstimator.FormShow(Sender: TObject);
begin
  if fFormAction='Edit' then
    begin
      frmEstimator.Caption := 'Edit Estimator';
      qryEstimatorMaintenance.ParamByName('IRN').AsInteger := fKey;
      qryEstimatorMaintenance.Open;
      qryEstimatorMaintenance.Edit;
    end
  else
    begin

    end;
end;
The correct record is being displayed on screen, and the user is allowed to edit it.

I am obviously missing something silly over here, could you please point me in the right direction.

Regards
Marius

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Can't perform operation on active transaction

Post by ViktorV » Tue 17 Jan 2017 09:18

InterBase/Firebird requires an active transaction for any operation with data, even for opening dataset. Therefore, when calling TIBCQuery.Open, it is verified if a transaction associated with it is running and, if it is not so - it is automatically run. In your example dataset uses a default transaction TUniConnection, therefore when attempting to call the Connection.StartTransaction method in your example, you get the "Can't perform operation on active transaction" error, because when opening dataset the transaction has already started.
To solve the issue you can use the following advice:
- change in your sample the string:

Code: Select all

qryEstimatorMaintenance.Transaction.StartTransaction;
into

Code: Select all

if not qryEstimatorMaintenance.Transaction.Active then                 qryEstimatorMaintenance.Transaction.StartTransaction;
- use for dataset a separate transaction, not a default transaction TIBCConnection;
- use for data modification UpdateTransaction.

mariusturnkey
Posts: 5
Joined: Mon 24 Aug 2015 19:04

Re: Can't perform operation on active transaction

Post by mariusturnkey » Tue 17 Jan 2017 09:49

Thank you Victor, I will do that.

I think this must be one of the differences to FIBPlus, I must just get to know what the differences are.

Thanks again.

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: Can't perform operation on active transaction

Post by ViktorV » Tue 17 Jan 2017 10:18

Thank you for being interested in our products.
If you have any questions during using our products, please don't hesitate to contact us - and we will try to help you solve them.

Post Reply