3

首先,我是 Delphi 的新手,所以这可能是一个被忽视的“平凡细节”。[提前抱歉]

'Invalid Transaction Object'当我尝试通过连接到Oracle 11g DB的 datasnap 服务器运行事务时出现错误。

由于系统细节和公司业务计划,我们选择不使用ClientDataSets来处理我们的交易。相反,我们试图使 Snap 服务器非常通用,并且只通过接收查询和返回本机类型来处理数据访问。

话虽如此,这里有一些让我很适合的示例代码:

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;
4

2 回答 2

3

通过调用SQLCon.DBXConnection.BeginTransaction(),您绕过了在调用SQLConnection 对象TTransactionItem时提交事务时检查的 internal 设置。SQLcon.CommitFreeAndNil()请注意,您是在DBXConnection对象上启动事务,但同样没有提交它。

代替

SQLCon.DBXConnection.BeginTransaction()

SQLCon.BeginTransaction()
于 2012-10-17T19:50:34.387 回答
0

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.

于 2018-06-15T19:07:26.110 回答