如何在三层内实现在客户端的后台查询(200分)

  • 主题发起人 主题发起人 WollyXF
  • 开始时间 开始时间
W

WollyXF

Unregistered / Unconfirmed
GUEST, unregistred user!
现有一SQL SERVER 2000+服务器+客户端 的应用系统
我如何实现在客户端的后台查询呢?
以下代码报错说:'Error read from socket';那位大侠能帮我搞定,你的代码也可以。[:(]
type
TWThread = class(TThread)
private
FrmQ: TSocketConnection;
FdspQ: String;
FcdsQ: TClientDataSet;
FdsQ: TdataSource;
protected
procedure Execute;
override;
public
constructor Create(rm: TSocketConnection;pn:String;
cds: TClientDataSet;
ds: TDataSource);virtual;
end;

{ TWThread }
constructor TWThread.Create(rm: TSocketConnection;pn:String;
cds: TClientDataSet;
ds: TDataSource);
begin
inherited Create(True);
FrmQ:= rm;
FdspQ:= pn;
FcdsQ:= cds;
FdsQ:= ds;
FrmQ.Address:='210.75.40.172';
FrmQ.ServerName:='DZSW_SERVER.rdmDZSW';
FrmQ.Connected:= True;
FreeOnTerminate:= True;
Resume;
end;

procedure TWThread.Execute;
begin
inherited;
with FcdsQdo
begin
Close;
RemoteServer:= FrmQ;;
ProviderName:= FdspQ;
CommandText:= 'Select * from tblrk';
Open;
end;
end;
 
类似的错误我也见过,原因是DELPHI中的MIDAS连接组件大都对多线程支持不好
(CORBA好一点),因为很多COM调用需要在同一线程中进行,还有CoInitialize
和CoUninitialize也需要调用。你可以在线程中创建连接以解决这一问题,结果
是多个线程不能使用同一连接(这也是应该避免的)。
下面是我改过的代码,可以正常连接:
unit Unit2;
interface
uses
Classes, Windows, DB, DBClient, MConnect, SConnect;
type
TWThread = class(TThread)
private
FrmQ: TSocketConnection;
//FdspQ: string;
FcdsQ: TClientDataSet;
//FdsQ: TdataSource;
protected
procedure Execute;
override;
public
constructor Create(rm: TSocketConnection;
cds: TClientDataSet);
virtual;
end;

implementation
{ TWThread }
constructor TWThread.Create(rm: TSocketConnection;
cds: TClientDataSet);
begin
inherited Create(True);
CoUninitialize
FrmQ := TSocketConnection.Create(nil);
FcdsQ := cds;
FrmQ.Address := rm.Address;
FrmQ.ServerName := rm.ServerName;
FrmQ.ServerGUID := rm.ServerGUID;
FreeOnTerminate := True;
Resume;
end;

procedure TWThread.Execute;
begin
Sleep(1000);
with FcdsQdo
begin
Close;
RemoteServer:= FrmQ;;
//ProviderName:= FdspQ;
Open;
end;
end;

end.

 
对了,线程结束时 FrmQ 要 FREE。
procedure TWThread.Execute;
begin
try
Sleep(1000);
with FcdsQdo
begin
Close;
RemoteServer := FrmQ;
;
//ProviderName:= FdspQ;
Open;
end;
finally
FrmQ.Free;
end;
end;
 
接受答案了.
 
后退
顶部