建立一个服务程序,在服务程序主窗口上放置一个TADOCONNECT控件,在主窗口上做数据库连接。服务程序中建立三个线程,三个线程中
都使用这个数据库连接。但是经常会发生某某线程连接导致另外一个命令这样的错误。请问:如何在线程中使用服务程序主窗口上建立的
数据库连接?还是每个线程单独建立数据库连接?
procedure TfrmMain.ServiceStart(Sender: TService; var Started: Boolean);
begin
CoInitialize(nil);
Conn.Connected :=True;
thReportLeaderShip:=TReportLeaderShip.Create(Conn,strProfixIni);
thReturnReportLeaderShip:=TReturnReportLeaderShip.Create(Conn,strProfixIni);
thXMLParse:=TXMLParse.Create(Conn);
thCreateReportXML:=TCreateReportXML.Create(Conn,strProfixIni);
Started:=True;
end;
  再请教:在服务程序中使用API中的WnetAddConnection2建立网络映射盘,建立的网络影射盘图标上带红叉,表示不能用,但是同样的程序在
普通的APPLICATION中建立的映射盘就可以使用,请问是不是服务程序中不能建立映射盘?如果能建立映射盘,该怎么做?
//下面是线程中可执行部分
procedure TReportLeaderShip.Execute;
var
NetSource : TNetResource;
begin
with NetSource do
begin
dwType := RESOURCETYPE_DISK;
lpLocalName := 'Z:'; //网络驱动器编号
lpRemoteName := PChar(NetString); //地址以及共享路径
lpProvider := nil;
end;
if WnetAddConnection2(NetSource, PChar(profixInI[2]), PChar(profixInI[1]), CONNECT_UPDATE_PROFILE)=NO_ERROR then
beginend;
end;