2

I am trying to stream a TClientDataSet using Datasnap in Delphi XE6. However, I keep getting a "Missing Data Provider or Data Packet" error on the client side code.

//Client

procedure TForm2.Button1Click(Sender: TObject);
var
 CDS: TClientDataSet;
 S: TStream;
begin
  CDS := TClientDataSet.Create(nil);
  try
    S:= ClientModule1.ServerMethods1Client.getCDSData;
    S.Seek(0,soFromBeginning);
    S.Position:= 0;
    CDS.LoadFromStream(S);
    CDS.Open; // Missing Data Provider or Data Packet
  finally
    CDS.Free;
  end;
end;

//Server

function TServerMethods1.getCDSData: TStream;
var
  Writer: TBinaryWriter;
  CDS: TClientDataSet;
  I: Integer;
begin
  result := TMemoryStream.Create;
  CDS := TClientDataSet.Create(nil);
  with CDS.FieldDefs do
  begin
    Clear;
    Add('First', ftString, 20);
    Add('Last', ftString, 25);
  end;
  CDS.CreateDataSet;
  CDS.Open;
  CDS.AppendRecord(['John', 'Smith']);
  CDS.AppendRecord(['Jane', 'Doe']);
  try
    CDS.SaveToStream(result);
  finally
    CDS.Free;
  end;
end;

I also tried Streaming it as XML instead of Binary

  CDS.SaveToStream(result, dfXML);

get the same error

"Missing Data Provider or Data Packet"

ANSWER:

CDS.SaveToStream(result);
Result.Position := 0; //need this in server method "getCDSData"
John
  • 507
  • 3
  • 13
  • 1
    What is the purpose of the `CDS.First; while not CDS.Eof do CDS.Next` loop, which accomplishes nothing? – Ken White May 26 '16 at 01:39
  • 3
    If I make getCDSData local to the TForm, the error does not occur and the data is transferred fine. So I think you need to look at your server. Have you tried running the server under the debugger while it executes getCDSData? – MartynA May 26 '16 at 07:19
  • Have you had a look into this example, which returns a TDataSet directly by a server method? https://sourceforge.net/p/radstudiodemos/code/HEAD/tree/branches/RadStudio_XE6/Object%20Pascal/DataSnap/Basic/ – Uwe Raabe May 26 '16 at 08:50
  • 1
    Hi MartynA, yes, I tested that as well and you are right, the streaming seems to work just fine when all code is placed in Client unit. – John May 26 '16 at 13:02
  • 1
    ahhh, turns out, in the server side method "getCDSData", I need a Result.Position := 0 after the Save to Stream. I will update the code above – John May 26 '16 at 15:53

1 Answers1

1
CDS.SaveToStream(result);
Result.Position := 0; 
John
  • 507
  • 3
  • 13
  • I am facing "Missing Data Provider or Data Packet" error on the client side code I tried the solution given above still it does not work. any comments on this would be really appreciated. – mano Nov 02 '17 at 06:11