看看错在那里 ClientDataSet 顶者有分 困扰我多时了 不够就加分:) ( 积分: 100 )

  • 主题发起人 主题发起人 luckj
  • 开始时间 开始时间
L

luckj

Unregistered / Unconfirmed
GUEST, unregistred user!
//出错提示 missing data provider or data packet
unit MyADO;
interface
uses
SysUtils,DB, ADODB, DBClient, Provider;
type
TMyDateUpdata = class
FADOQ: TADOQuery;
FDSProvider: TDataSetProvider;
FClientDataSet: TClientDataSet;
FADOConn: TADOConnection;
public
constructor Create(Conn:string);
destructor Destroy;
function UpdateXMLTODB(XMLPath:string):boolean;
end;

implementation
uses unit1;


{ TMyDateUpdata }

constructor TMyDateUpdata.Create(Conn:string);
begin
FADOConn:= TADOConnection.Create(nil);
FADOQ:= TADOQuery.Create(Nil);
FClientDataSet:= TClientDataSet.Create(nil);
FDSProvider:= TDataSetProvider.Create(nil);
//设置FADOConn
FADOConn.CommandTimeout:=30;
FADOConn.ConnectionString:= Conn;
FADOConn.ConnectionTimeout:=15;
FADOConn.CursorLocation := clUseClient;
FADOConn.ConnectOptions:= coConnectUnspecified;
FADOConn.KeepConnection :=true;
FADOConn.LoginPrompt :=false;
FADOConn.Provider:= 'SQLOLEDB.1';

//设置FADOQ
FADOQ.Connection :=FADOConn;
FADOQ.AutoCalcFields :=true;
FADOQ.CacheSize :=2;
FADOQ.CommandTimeout :=30;
FADOQ.CursorLocation :=clUseClient;
FADOQ.CursorType := ctStatic;
FADOQ.LockType:= ltOptimistic;
FADOQ.MarshalOptions := moMarshalAll;
FADOQ.ParamCheck:=true;
//设置FDSProvider
FDSProvider.Name := 'FDSProvider' ;
FDSProvider.DataSet:= FADOQ;
FDSProvider.Exported:=true;
FDSProvider.ResolveToDataSet:=false;
FDSProvider.UpdateMode:=upWhereKeyOnly;
FDSProvider.Options := [poallowcommandtext];
//设置FClientDataSet
FClientDataSet.AggregatesActive:=false;
FClientDataSet.AutoCalcFields:=true;
FClientDataSet.DisableStringTrim :=false;
FClientDataSet.FetchOnDemand:=true;
FClientDataSet.ObjectView :=true;
FClientDataSet.ReadOnly :=false;
FClientDataSet.StoreDefs :=true;
FClientDataSet.ProviderName := FDSProvider.Name ;

//test
FADOConn.Connected:=true;
FClientDataSet.CommandText :='select * from Employees';
FClientDataSet.Active :=true;//出错 missing data provider or data packet

end;

destructor TMyDateUpdata.Destroy;
begin
FADOQ.Close;
Freeandnil(FADOQ) ;
Freeandnil(FDSProvider) ;
Freeandnil(FClientDataSet) ;
Freeandnil(FADOConn) ;
end;

function TMyDateUpdata.UpdateXMLTODB(XMLPath: string):boolean;
begin
Result:=true;
if self <>nil then
begin
try
FClientDataSet.LoadFromFile(XMLPath);
FClientDataSet.ApplyUpdates(0);
except
Result:=false;
end;
end
else
Result:=false;
end;

end.
 
//出错提示 missing data provider or data packet
unit MyADO;
interface
uses
SysUtils,DB, ADODB, DBClient, Provider;
type
TMyDateUpdata = class
FADOQ: TADOQuery;
FDSProvider: TDataSetProvider;
FClientDataSet: TClientDataSet;
FADOConn: TADOConnection;
public
constructor Create(Conn:string);
destructor Destroy;
function UpdateXMLTODB(XMLPath:string):boolean;
end;

implementation
uses unit1;


{ TMyDateUpdata }

constructor TMyDateUpdata.Create(Conn:string);
begin
FADOConn:= TADOConnection.Create(nil);
FADOQ:= TADOQuery.Create(Nil);
FClientDataSet:= TClientDataSet.Create(nil);
FDSProvider:= TDataSetProvider.Create(nil);
//设置FADOConn
FADOConn.CommandTimeout:=30;
FADOConn.ConnectionString:= Conn;
FADOConn.ConnectionTimeout:=15;
FADOConn.CursorLocation := clUseClient;
FADOConn.ConnectOptions:= coConnectUnspecified;
FADOConn.KeepConnection :=true;
FADOConn.LoginPrompt :=false;
FADOConn.Provider:= 'SQLOLEDB.1';

//设置FADOQ
FADOQ.Connection :=FADOConn;
FADOQ.AutoCalcFields :=true;
FADOQ.CacheSize :=2;
FADOQ.CommandTimeout :=30;
FADOQ.CursorLocation :=clUseClient;
FADOQ.CursorType := ctStatic;
FADOQ.LockType:= ltOptimistic;
FADOQ.MarshalOptions := moMarshalAll;
FADOQ.ParamCheck:=true;
//设置FDSProvider
FDSProvider.Name := 'FDSProvider' ;
FDSProvider.DataSet:= FADOQ;
FDSProvider.Exported:=true;
FDSProvider.ResolveToDataSet:=false;
FDSProvider.UpdateMode:=upWhereKeyOnly;
FDSProvider.Options := [poallowcommandtext];
//设置FClientDataSet
FClientDataSet.AggregatesActive:=false;
FClientDataSet.AutoCalcFields:=true;
FClientDataSet.DisableStringTrim :=false;
FClientDataSet.FetchOnDemand:=true;
FClientDataSet.ObjectView :=true;
FClientDataSet.ReadOnly :=false;
FClientDataSet.StoreDefs :=true;
FClientDataSet.ProviderName := FDSProvider.Name ;

//test
FADOConn.Connected:=true;
FClientDataSet.CommandText :='select * from Employees';
FClientDataSet.Active :=true;//出错 missing data provider or data packet

end;

destructor TMyDateUpdata.Destroy;
begin
FADOQ.Close;
Freeandnil(FADOQ) ;
Freeandnil(FDSProvider) ;
Freeandnil(FClientDataSet) ;
Freeandnil(FADOConn) ;
end;

function TMyDateUpdata.UpdateXMLTODB(XMLPath: string):boolean;
begin
Result:=true;
if self <>nil then
begin
try
FClientDataSet.LoadFromFile(XMLPath);
FClientDataSet.ApplyUpdates(0);
except
Result:=false;
end;
end
else
Result:=false;
end;

end.
 
帮你顶一下
关注...
 
ClientDataSet->DataSetProvider->ADOQuery->ADOConnection
这样的连接方式很明显只能利用ADOQuery通过SQL获取数据
如果楼主想利用ClientDataSet的方式管理数据建议看看DBExpress吧
 
呀!没注意看DataSetProvider.Options := [poallowcommandtext];
[:D][:D](不好意思)
 
我看不懂
 
终于找到原因喽!
看看DBClient单元吧!
procedure CheckCircularLinks;
var
ProvComp: TComponent;
begin
if Assigned(MasterSource) and Assigned(Owner) and (not Assigned(RemoteServer))
and (ProviderName <> '') and (not Assigned(ConnectionBroker)) then
begin
[red]ProvComp := Owner.FindComponent(ProviderName);[/red]
if Assigned(ProvComp) and (ProvComp is TDataSetProvider) and
Assigned(MasterSource.DataSet) and
Assigned(TDataSetProvider(ProvComp).DataSet) then
if TDataSetProvider(ProvComp).DataSet = MasterSource.DataSet then
DatabaseError(SCircularDataLink, MasterSource.DataSet);
end;
end;
ClientDataSet是通过它的Owner.FindComponent查找ProviderName的DataSetProvider,而你的ClientDataSet.Create(Nil)和DataSetProvider.Create(nil)导致ClientDataSet无法正确找到DataSetProvider
 
解决办法把TMyDateUpdata.Create(Conn:string);
改成TMyDateUpdata.Create(Conn:string; MyOwner:TComponent);
然后建立那堆东东的时候什么加上create(MyOwner)就可以了
MyOwner最好传入窗体或者是Datamodule之类的东东
 
谢谢你的解答!!create(MyOwner) ,假设MyOwner是窗体时,窗体关闭自动会free这几个动态创建的对象,这些对象在有要能在窗体关闭前就free了。有没有更好的方法:) 能告诉我你是怎么找到这个错误的,我以前有看一下DBClient单元,就是没法找到问题所在。偶好笨呀:)
 
更好的办法是直接修改ClientDataSet源码,导出一属性直接指向需要的DataSetProvider
当然这样做会有其它什么影响就不知道喽!
(为什么borland要这样设计ClientDataSet肯定是有原因的
 
piao40993470
好的谢谢哦!能交个朋友吗?QQ:5938665 有什么事可能讨论讨论。可以加我的话 说明一下delphibbs :)
 
最好通过email吧,我开Q和msn的时间都很少,因为上班时间不允许开这两个东西。
xbpiao@msn.com[:D]
 
后退
顶部