Steve F
Steve F

Reputation: 1587

TClientDataSet error: "Missing data provider or data packet"

I'm creating a TClientDataSet and TDataSetProvider in code in Delphi, and loading the data from a TUniQuery (Devart UniDAC). After setting the properties for the dataset provider and the clientdataset, I try to open the clientdataset and get the runtime exception: "Missing data provider or data packet".

I'm not sure why its happening and would be glad if anyone could point out what exactly is wrong.

This is my code:

//uq is a TUniQuery correctly set to an active TUniConnection

cdsFirstNames := TClientDataSet.Create(nil);
dspFirstNames := TDataSetProvider.Create(nil);
try
  uq.SQL.Text := 'SELECT * FROM firstnames;';
  uq.Prepared := True;
  // uq.Open;
  dspFirstNames.Name := 'dspFirstNames';
  dspFirstNames.DataSet := uq;
  cdsFirstNames.ProviderName := 'dspFirstNames';
  cdsFirstNames.Open;  // <--- Exception occurs here!
  uq.Close;
  showmessage(IntToStr(cdsFirstNames.RecordCount));

Upvotes: 1

Views: 17826

Answers (1)

Val Marinov
Val Marinov

Reputation: 2755

If DatasetProvider has no owner, ClientDataSet can not obtain a reference to the provider.

So use

...Create(Self); 

instead of

...Create(nil);

Upvotes: 6

Related Questions