Question

1st off I am new to Delphi so this may be a "mundane detail" that's being over looked. [sorry in advance]

I am getting an 'Invalid Transaction Object' error when I attempt to run a transaction through a datasnap server connected to an Oracle 11g DB.

Due to the system details and the companies business plan we have elected not to use ClientDataSets to handle our transactions. Instead we are attempting to make the Snap server very generic and only handle data access by receiving queries and returning native types.

With that being said here is some sample code that is giving me fits:

function TSnapMethods.TransUpdate: boolean;
var
  dbx: TDBXTransaction;
  params:TParams;
begin
  SqlCon.Open;
  dbx := SQLCon.DBXConnection.BeginTransaction(TDBXIsolations.ReadCommitted);
  try
      params:= TParams.Create(self);
      with Params.AddParameter do
      begin
        name:= 'param';
        DataType:= ftWideString;
        ParamType:= ptInput;
        asString:= 'Bugsville';
      end;
      with Params.AddParameter do
      begin
        name:= 'var';
        DataType:= ftWideString;
        ParamType:= ptInput;
        asString:= 'ZZZTOP';
      end;
      sqlcon.Execute('Update Name set City=:param Where Abrv=:var',params);

      SQLcon.CommitFreeAndNil(dbx);//Breaks here...
      result:= true;
  except
    Sqlcon.RollbackFreeAndNil(dbx);//Breaks here also...
    result:= false;
  end;        
end;
Was it helpful?

Solution

By calling SQLCon.DBXConnection.BeginTransaction(), you're bypassing the setting up of internal TTransactionItem which is checked when the transaction is committed when you call SQLcon.CommitFreeAndNil() on the SQLConnection object. Notice that you're starting the transaction on the DBXConnection object but not committing it likewise.

Replace

SQLCon.DBXConnection.BeginTransaction()

with

SQLCon.BeginTransaction()

OTHER TIPS

From another source I got this helpful information: http://codeverge.com/embarcadero.delphi.ide/record-not-found-or-changed-by-another/1061559

For start transaction:

transaction:=Datamodule.SqlConection.BeginTransaction(TDBXIsolations.ReadCommitted);

For commit:

DataModule1.SqlConection.CommitFreeAndNil(Transacao);

To rollback:

DataModule1.SqlConection.RollbackIncompleteFreeAndNil(Transacao)  

And use

RollbackIncompleteFreeAndNil

instead

RollbackIncompleteFreeAndNil

like referenced by:

http://docwiki.embarcadero.com/Libraries/Tokyo/en/Data.SqlExpr.TSQLConnection.RollbackIncompleteFreeAndNil

Please try this and report the results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top