Search code examples
delphitclientdataset

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));

Solution

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

    So use

    ...Create(Self); 
    

    instead of

    ...Create(nil);