FConnect:=TSocketConnection.Create(mainform);
FConnect.loginprompt:=false;
FConnect.ServerName:='Server.GetData';
FConnect.ServerGUID:='{1EBF8414-9C13-473C-B555-8823650F04EA}';
FConnect.Address:='192.168.0.24';
FConnect.Port:=211;
Fconnect.SupportCallbacks:=true;
Fconnect.Connected :=true;
.
.
.
query:=TClientDataSet.Create(mainform);
query.RemoteServer:=FConnect;
query.ProviderName:='SyProvider1';
query.ReadOnly:=false;
query.AggregatesActive:=false;
query.ObjectView:=true;
query.AutoCalcFields:=true;
query.Active:=false;
query.Active:=false;
tempstr:='Select * from table1';
FConnect.AppServer.setsql(tempstr,'SYDS1'); //这一步可以 ,打开和SyProvider1相关联的服务器端的ADO纪录集合,这样可以返回到客户端的TClientDataSet
query.Active:=true; //有错,总打不开,向各位大虾求救(是不是再封装的对象内不能这么用)
8 个解决方案
#1
试试在服务端的setsql方法中只修改Sql查询,不打开数据庥,在客户数据集要求数据的时候,远程的数据集会自动打开
#2
报什么错?
#3
谢谢,各位
错误提示“EDBClient Invalid parameters”,可是我不需要什么参数呀,我配置的都对,涉及到那些问题呀?
错误提示“EDBClient Invalid parameters”,可是我不需要什么参数呀,我配置的都对,涉及到那些问题呀?
#4
检查你的ClientDataSet的Params的内容
#5
我不需要设置参数!!!只是再服务器上执行完'Select * from table1'后,我再客户端能够得到
但是我不用封装的对象,在外面调试这段程序可以完成操作
FConnect.AppServer.setsql(tempstr,'SYDS1');
query.Active:=true; 可以正常运行
是不是在封装的对象内不能这样运行呀
但是我不用封装的对象,在外面调试这段程序可以完成操作
FConnect.AppServer.setsql(tempstr,'SYDS1');
query.Active:=true; 可以正常运行
是不是在封装的对象内不能这样运行呀
#6
还有,ClientDataset的CommandText什么情况下我可以在客户端设置运行呀
比如
ClientDataset1.commandtext:='Select * from table1';
ClientDataset1.open;
我感觉再服务器上运行不能共享执行
比如
ClientDataset1.commandtext:='Select * from table1';
ClientDataset1.open;
我感觉再服务器上运行不能共享执行
#7
你换种简单的方法试试吧..
服务端:
function TContractServer.DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
begin
with ADOQuery1 do
begin
Close;
sql.Clear;
sql.Add(input);
open;
end;
result:=DataSetProvider1.Data;
end;
客户端:
frmDM.ClientDataSet1.Close; frmDM.ClientDataSet1.Data:=frmDM.ClientDataSet1.DataRequest('select * from tab);
frmDM.ClientDataSet1.Open;
服务端:
function TContractServer.DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
begin
with ADOQuery1 do
begin
Close;
sql.Clear;
sql.Add(input);
open;
end;
result:=DataSetProvider1.Data;
end;
客户端:
frmDM.ClientDataSet1.Close; frmDM.ClientDataSet1.Data:=frmDM.ClientDataSet1.DataRequest('select * from tab);
frmDM.ClientDataSet1.Open;
#8
没发现类似的问题
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, SConnect, StdCtrls, Buttons, Grids,
DBGrids;
type
TTest = class
public
function GetData(SqlStr: string): OleVariant;
end;
TForm2 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
BitBtn1: TBitBtn;
ClientDataSet1: TClientDataSet;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TTest }
function TTest.GetData(SqlStr: string): OleVariant;
var
FConnect: TSocketConnection;
query: TClientDataSet;
begin
FConnect := TSocketConnection.Create(nil);
FConnect.loginprompt := false;
FConnect.ServerName := 'Server.GetData';
FConnect.ServerGUID := '{1EBF8414-9C13-473C-B555-8823650F04EA}';
FConnect.Address := '127.0.0.1';
FConnect.Port := 211;
Fconnect.SupportCallbacks := true;
Fconnect.Connected := true;
FConnect.AppServer.setsql(SqlStr, 'SYDS1');
query := TClientDataSet.Create(nil);
query.RemoteServer := FConnect;
query.ProviderName := 'SyProvider1';
query.ReadOnly := false;
query.AggregatesActive := true;
query.ObjectView := true;
query.Aggregates.Clear;
query.Params.Clear;
query.Constraints.Clear;
query.FieldDefs.Clear;
query.AutoCalcFields := true;
try
try
query.Active := True;
Result := query.Data;
except
Result := null;
raise;
end;
finally
FreeAndNil(FConnect);
FreeAndNIl(query);
end;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
var
test1: TTest;
begin
test1 := TTest.Create;
if ClientDataSet1.Active then
ClientDataSet1.Active := False;
try
ClientDataSet1.Data := test1.GetData('select * from khda');
ClientDataSet1.Active := True;
finally
FreeAndNil(test1);
end;
end;
procedure TForm2.BitBtn2Click(Sender: TObject);
var
test1: TTest;
begin
test1 := TTest.Create;
if ClientDataSet1.Active then
ClientDataSet1.Active := False;
try
ClientDataSet1.Data := test1.GetData('select * from cpda');
ClientDataSet1.Active := True;
finally
FreeAndNil(test1);
end;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, SConnect, StdCtrls, Buttons, Grids,
DBGrids;
type
TTest = class
public
function GetData(SqlStr: string): OleVariant;
end;
TForm2 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
BitBtn1: TBitBtn;
ClientDataSet1: TClientDataSet;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TTest }
function TTest.GetData(SqlStr: string): OleVariant;
var
FConnect: TSocketConnection;
query: TClientDataSet;
begin
FConnect := TSocketConnection.Create(nil);
FConnect.loginprompt := false;
FConnect.ServerName := 'Server.GetData';
FConnect.ServerGUID := '{1EBF8414-9C13-473C-B555-8823650F04EA}';
FConnect.Address := '127.0.0.1';
FConnect.Port := 211;
Fconnect.SupportCallbacks := true;
Fconnect.Connected := true;
FConnect.AppServer.setsql(SqlStr, 'SYDS1');
query := TClientDataSet.Create(nil);
query.RemoteServer := FConnect;
query.ProviderName := 'SyProvider1';
query.ReadOnly := false;
query.AggregatesActive := true;
query.ObjectView := true;
query.Aggregates.Clear;
query.Params.Clear;
query.Constraints.Clear;
query.FieldDefs.Clear;
query.AutoCalcFields := true;
try
try
query.Active := True;
Result := query.Data;
except
Result := null;
raise;
end;
finally
FreeAndNil(FConnect);
FreeAndNIl(query);
end;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
var
test1: TTest;
begin
test1 := TTest.Create;
if ClientDataSet1.Active then
ClientDataSet1.Active := False;
try
ClientDataSet1.Data := test1.GetData('select * from khda');
ClientDataSet1.Active := True;
finally
FreeAndNil(test1);
end;
end;
procedure TForm2.BitBtn2Click(Sender: TObject);
var
test1: TTest;
begin
test1 := TTest.Create;
if ClientDataSet1.Active then
ClientDataSet1.Active := False;
try
ClientDataSet1.Data := test1.GetData('select * from cpda');
ClientDataSet1.Active := True;
finally
FreeAndNil(test1);
end;
end;
end.
#1
试试在服务端的setsql方法中只修改Sql查询,不打开数据庥,在客户数据集要求数据的时候,远程的数据集会自动打开
#2
报什么错?
#3
谢谢,各位
错误提示“EDBClient Invalid parameters”,可是我不需要什么参数呀,我配置的都对,涉及到那些问题呀?
错误提示“EDBClient Invalid parameters”,可是我不需要什么参数呀,我配置的都对,涉及到那些问题呀?
#4
检查你的ClientDataSet的Params的内容
#5
我不需要设置参数!!!只是再服务器上执行完'Select * from table1'后,我再客户端能够得到
但是我不用封装的对象,在外面调试这段程序可以完成操作
FConnect.AppServer.setsql(tempstr,'SYDS1');
query.Active:=true; 可以正常运行
是不是在封装的对象内不能这样运行呀
但是我不用封装的对象,在外面调试这段程序可以完成操作
FConnect.AppServer.setsql(tempstr,'SYDS1');
query.Active:=true; 可以正常运行
是不是在封装的对象内不能这样运行呀
#6
还有,ClientDataset的CommandText什么情况下我可以在客户端设置运行呀
比如
ClientDataset1.commandtext:='Select * from table1';
ClientDataset1.open;
我感觉再服务器上运行不能共享执行
比如
ClientDataset1.commandtext:='Select * from table1';
ClientDataset1.open;
我感觉再服务器上运行不能共享执行
#7
你换种简单的方法试试吧..
服务端:
function TContractServer.DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
begin
with ADOQuery1 do
begin
Close;
sql.Clear;
sql.Add(input);
open;
end;
result:=DataSetProvider1.Data;
end;
客户端:
frmDM.ClientDataSet1.Close; frmDM.ClientDataSet1.Data:=frmDM.ClientDataSet1.DataRequest('select * from tab);
frmDM.ClientDataSet1.Open;
服务端:
function TContractServer.DataSetProvider1DataRequest(Sender: TObject;
Input: OleVariant): OleVariant;
begin
with ADOQuery1 do
begin
Close;
sql.Clear;
sql.Add(input);
open;
end;
result:=DataSetProvider1.Data;
end;
客户端:
frmDM.ClientDataSet1.Close; frmDM.ClientDataSet1.Data:=frmDM.ClientDataSet1.DataRequest('select * from tab);
frmDM.ClientDataSet1.Open;
#8
没发现类似的问题
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, SConnect, StdCtrls, Buttons, Grids,
DBGrids;
type
TTest = class
public
function GetData(SqlStr: string): OleVariant;
end;
TForm2 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
BitBtn1: TBitBtn;
ClientDataSet1: TClientDataSet;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TTest }
function TTest.GetData(SqlStr: string): OleVariant;
var
FConnect: TSocketConnection;
query: TClientDataSet;
begin
FConnect := TSocketConnection.Create(nil);
FConnect.loginprompt := false;
FConnect.ServerName := 'Server.GetData';
FConnect.ServerGUID := '{1EBF8414-9C13-473C-B555-8823650F04EA}';
FConnect.Address := '127.0.0.1';
FConnect.Port := 211;
Fconnect.SupportCallbacks := true;
Fconnect.Connected := true;
FConnect.AppServer.setsql(SqlStr, 'SYDS1');
query := TClientDataSet.Create(nil);
query.RemoteServer := FConnect;
query.ProviderName := 'SyProvider1';
query.ReadOnly := false;
query.AggregatesActive := true;
query.ObjectView := true;
query.Aggregates.Clear;
query.Params.Clear;
query.Constraints.Clear;
query.FieldDefs.Clear;
query.AutoCalcFields := true;
try
try
query.Active := True;
Result := query.Data;
except
Result := null;
raise;
end;
finally
FreeAndNil(FConnect);
FreeAndNIl(query);
end;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
var
test1: TTest;
begin
test1 := TTest.Create;
if ClientDataSet1.Active then
ClientDataSet1.Active := False;
try
ClientDataSet1.Data := test1.GetData('select * from khda');
ClientDataSet1.Active := True;
finally
FreeAndNil(test1);
end;
end;
procedure TForm2.BitBtn2Click(Sender: TObject);
var
test1: TTest;
begin
test1 := TTest.Create;
if ClientDataSet1.Active then
ClientDataSet1.Active := False;
try
ClientDataSet1.Data := test1.GetData('select * from cpda');
ClientDataSet1.Active := True;
finally
FreeAndNil(test1);
end;
end;
end.
unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, DB, DBClient, MConnect, SConnect, StdCtrls, Buttons, Grids,
DBGrids;
type
TTest = class
public
function GetData(SqlStr: string): OleVariant;
end;
TForm2 = class(TForm)
DataSource1: TDataSource;
DBGrid1: TDBGrid;
BitBtn1: TBitBtn;
ClientDataSet1: TClientDataSet;
BitBtn2: TBitBtn;
procedure BitBtn1Click(Sender: TObject);
procedure BitBtn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form2: TForm2;
implementation
{$R *.dfm}
{ TTest }
function TTest.GetData(SqlStr: string): OleVariant;
var
FConnect: TSocketConnection;
query: TClientDataSet;
begin
FConnect := TSocketConnection.Create(nil);
FConnect.loginprompt := false;
FConnect.ServerName := 'Server.GetData';
FConnect.ServerGUID := '{1EBF8414-9C13-473C-B555-8823650F04EA}';
FConnect.Address := '127.0.0.1';
FConnect.Port := 211;
Fconnect.SupportCallbacks := true;
Fconnect.Connected := true;
FConnect.AppServer.setsql(SqlStr, 'SYDS1');
query := TClientDataSet.Create(nil);
query.RemoteServer := FConnect;
query.ProviderName := 'SyProvider1';
query.ReadOnly := false;
query.AggregatesActive := true;
query.ObjectView := true;
query.Aggregates.Clear;
query.Params.Clear;
query.Constraints.Clear;
query.FieldDefs.Clear;
query.AutoCalcFields := true;
try
try
query.Active := True;
Result := query.Data;
except
Result := null;
raise;
end;
finally
FreeAndNil(FConnect);
FreeAndNIl(query);
end;
end;
procedure TForm2.BitBtn1Click(Sender: TObject);
var
test1: TTest;
begin
test1 := TTest.Create;
if ClientDataSet1.Active then
ClientDataSet1.Active := False;
try
ClientDataSet1.Data := test1.GetData('select * from khda');
ClientDataSet1.Active := True;
finally
FreeAndNil(test1);
end;
end;
procedure TForm2.BitBtn2Click(Sender: TObject);
var
test1: TTest;
begin
test1 := TTest.Create;
if ClientDataSet1.Active then
ClientDataSet1.Active := False;
try
ClientDataSet1.Data := test1.GetData('select * from cpda');
ClientDataSet1.Active := True;
finally
FreeAndNil(test1);
end;
end;
end.