function TEANService.GetEANS(EanCode : ansistring): TStream; var LResult : TMemoryStream; begin LResult := TMemoryStream.Create; DbController.GetEans(EanCode,LResult);
Result := LResult; end;
Then from teh DB side the following:
procedure TDbController.GetEans(EanCode : string; AStream: TStream); begin if Assigned ( AStream ) then begin EANQuery.Close; EANQuery.Connection := Connection; EANQuery.Prepared := False; if not EANQuery.Prepared then begin EANQuery.SQL.Add('SELECT AEA_REFNUMMER'); EANQuery.SQL.Add('FROM V_ART_EANS'); EANQuery.SQL.Add('WHERE AEA_EANCODE = ''' + EanCode + ''''); end; EANQuery.Open; EANQuery.SaveToStream(AStream, sfJSON); end; end;
Would you mind to share the solution for other users?
From what I see in your code, the culprit should be in this line:
DbController.GetEans
You are using a global instance of DbController and that shouldn't be done in a multithread environment like XData, where multiple client requests are being processed at the same time. In each request, create a local instance of TDbController object and the release it at the end of the request.