XData Sever

Hello

I am relativly new to xData, but finding it very good and quick to program.

I have a Xdata sever linked to a DB, so when i send a http request with a paramter i get back a value.
for the first request when i send the call, all work fine, i get back the correct value.

For all subsequant calls, whern a send a differnt paramter, my return valus is the same as from the first request and not the correct value.

Example First call from starting the Xdata Sever:
Call 1: http://localhost/flix/EANService/GetEans?EanCode=123456789
Return Value = 10016 (Correct)

Example Second call:
Return Value = 10016 (Incorrect), should be 10023

Thiw was tested directly on the Web Browser & Swagger.


Hope this makes sense

Many thanks

Hi David,

I'm glad you are enjoying XData!
Regarding your question, I believe the answer lies in the implementation of your GetEans method. Can you please provide it?
Hello Wagner,
Many thanks for your feedback

So from teh service sode i ahve the following:
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;

Many thanks

Hello,

This issue has now been resolved.....

Thank you.

Hello David,

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.