Getting invalid transaction handle when creating the components in code

Discussion of open issues, suggestions and bugs regarding IBDAC (InterBase Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
danielrail
Posts: 11
Joined: Tue 10 Feb 2015 18:22

Getting invalid transaction handle when creating the components in code

Post by danielrail » Tue 10 Feb 2015 19:12

Hi,

I'm currently using Delphi XE7 with IBDAC 5.4.12.

I have the following code in a procedure, that is located in a simple unit(not a form nor a datamodule):

Code: Select all

var
  vDB: TIBCConnection;
  vTR: TIBCTransaction;
  vQuery: TIBCSQL;
begin
  vDB := TIBCConnection.Create(nil);
  vTR := TIBCTransaction.Create(nil);
  vQuery := TIBCSQL.Create(nil);
  try
    vTR.DefaultConnection := vDB;
    vTR.IsolationLevel := iblReadCommitted;
    vDB.DefaultTransaction := vTR;
    vDB.AutoCommit := False;
    vQuery.AutoCommit := False;
    SetupIBDACConnection(vDB, Demo); // A procedure that populates the TIBCConnection properties.
    vDB.Open;
    vQuery.Transaction := vTR;
    vTR.StartTransaction;
    vQuery.SQL.Add('INSERT INTO PATIENT_ACCESS_LOG ');
    vQuery.SQL.Add
      (' (PATIENTNO, SECTION, DESCRIPTION_TEXT, USERNAME, PAL_DATE, PAL_TIMESTAMP, EMPLOYEE_ID) ');
    vQuery.SQL.Add(' VALUES (' + IntToStr(PatientNo) + ', ''' + Section +
      ''', ''' + DescriptionText + ''', ''' + Username +
      ''', CURRENT_DATE, CURRENT_TIMESTAMP, ' + IntToStr(Employee_ID) + ') ');
    vQuery.Execute;
  finally
    if vTR.Active then
      vTR.Commit;
    if vDB.Connected then
      vDB.Disconnect;
    if Assigned(vQuery) then
      vQuery.Free;
    if Assigned(vTR) then
      vTR.Free;
    if Assigned(vDB) then
      vDB.Free;
  end;
end;
And, I get the following error at the line "vQuery.Execute": "Invalid transaction handle (expecting explicit transaction start)".

All I did was simply converted this code from FIB Plus(in Delphi 7) to IBDAC(in Delphi XE7). The code worked with FIB Plus(in Delphi 7), but I'm wondering if there is something different that I should do for IBDAC.

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

Re: Getting invalid transaction handle when creating the components in code

Post by ViktorV » Wed 11 Feb 2015 09:14

Unfortunately, we could not reproduce the issue. Your sample code works without any errors. Please compose a full sample project to demonstrate the issue to viktorv*devart*com, including a script to create and fill in the test database object.

danielrail
Posts: 11
Joined: Tue 10 Feb 2015 18:22

Re: Getting invalid transaction handle when creating the components in code

Post by danielrail » Wed 11 Feb 2015 12:23

Hi,

Thanks for the quick response.

I found the problem. I forgot to assign the Connection property of vQuery (vQuery.Connection := vDB). I added that line just before the line where I assign the transaction property, and everything works.

I'm just wondering if FIB Plus automatically assigns the connection component related to the transaction component, but anyway it made me look elsewhere to make certain that the properties are explicitly assigned. And actually, I do prefer to have to explicitly assign the properties, as this gives me the certainty of which components are used and when.

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

Re: Getting invalid transaction handle when creating the components in code

Post by ViktorV » Thu 12 Feb 2015 08:39

Glad to see that the issue was resolved. Feel free to contact us if you have any further questions about IBDAC.

Post Reply