TClientDataSet error: “Missing data provider or data packet”

纵然是瞬间 提交于 2021-01-28 10:05:38

问题


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

回答1:


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

So use

...Create(Self); 

instead of

...Create(nil);


来源:https://stackoverflow.com/questions/29987104/tclientdataset-error-missing-data-provider-or-data-packet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!