遇到个奇怪的问题,同时开启本地和远程两个事务,远程事务是sql2000没问题,是sql2008的不报错,但是写不上数据。
倒腾了4、5天,找到最终的解决办法:直接调用AdoConnection.execute(sq脚本),看来AdoQuery调用AdoConnection的还是有兼容性问题。
代码如下:
Function TDM_Base.PassMarkBill(AQuery:TAdoQuery; lTrans:Boolean=True;
sID:String=''; sMachineID:String=''; sUserName:String='';
nAddinRate:Real=1; lAllowNegative:Boolean=True; lUpdateLastDate:Boolean=True):Boolean;
Var qry, qryR:TAdoQuery;
n:Real; lT:Boolean;
sErrMsg, sSql:string;
Begin
Result:=False; qryR:=nil;
Qry:=AQuery;
if not assigned(qry) then qry:=qry_R;
qryR:=getNewAdoQuery(qry.connection); //getNewAdoQuery(qry.connection);
sErrMsg:='';
With QryR do
Try
Close;
lT:=false;
if lTrans and (not connection.inTransaction) then begin
connection.BeginTrans;
lT:=true;
end;
//**************************调用执行sql存储过程***********************//
//20160727特别说明:用AdoQuery直接执行,在连接远程的事务中,会出现莫名其妙的错误
//下面屏蔽掉了的代码,执行完了不报错,但是在Frm_SalePos.SaveData中,
//调用iBaseBiz.moveMarkBill时,然后调用这里,会导致莫名其妙的错误,
//程序不报错,但是服务器那头没数据,事务自己撤销了
//********************************************************************//
sql.text:='declare @n real ';
sql.add('exec @n=passMarkBill '+quotedStr(sID)+', '+quotedStr(sUserName)+', '+
floatToStr(nAddinRate)+', '+iif(lAllowNegative,'1','0')+', '+iif(lUpdateLastDate,'1','0')+' ');
//sql.add(' exec @n=passMarkBill :sID, :sUser, :nRate, :lAllowNegative, :lUpdateLastDate ');
sql.add('select @n as nResult ');
//parameters.ParamValues['sID']:=sID;
//parameters.ParamValues['sUser']:=sUserName;
//parameters.ParamValues['nRate']:=nAddinRate;
//parameters.ParamValues['lAllowNegative']:=lAllowNegative;
//parameters.ParamValues['lUpdateLastDate']:=lUpdateLastDate;
//open; //execSql
sSql:=sql.text;
connection.Execute(sSql); //******用最底层的连接执行没问题********//
//n:=fields[0].Value;
//if n<>0 then raise exception.Create('审核出错!返回值非零。'+floatToStr(n));
//写日志
writeSysLog(qryR, sID, sID+'审核积分单据', self.name+'.PassMarkBill');
//
if lT then connection.CommitTrans;
Result:=True;
Except
On x:Exception do begin
if lT then connection.RollbackTrans;
sErrMsg:='[PassMarkBill]审核积分单'+sID+'出错!'#13+x.message;
End;
End;
if assigned(qryR) then freeAndNil(qryR);
if sErrMsg<>'' then Raise Exception.Create(sErrMsg);
End;