搞了一个上午了,没有结果,翻遍了CSDN也没找到答案。
启动是显示“本地计算机上的服务启动有停止了。一些服务自动停止....”
事件查看器中的错误是“事件 ID ( 0 )的描述(在资源( CreateFile )中)无法找到。本地计算机可能没有必要的注册信息或消息 DLL 文件来从远程计算机显示消息。您可能可以使用 /AUXSOURCE= 标识来检索词描述;查看帮助和支持以了解详细信息。下列信息是事件的一部分: Service failed on start: 尚未调用 CoInitialize。.”,在服务及线程中都加了initialization
begin
  CoInitialize(nil);
end;
也不行,与代码如下:
procedure TCreateLFile.ServiceStart(Sender: TService;
  var Started: Boolean);
begin
  MainConn.ConnectionString:='......';//TADO连接对象
  MainConn.Connected:=True;
  CXML:=TGenerateRss.Create(MainConn);
  CXML.Resume;
  Started:=True;
end;procedure TCreateFile.ServiceStop(Sender: TService;
  var Stopped: Boolean);
begin
  CXML.Terminate;
  Stopped:=True;
end;procedure TCreateFile.ServicePause(Sender: TService;
  var Paused: Boolean);
begin
  CXML.Suspend;
  Paused:=True;
end;procedure TCreateFile.ServiceContinue(Sender: TService;
  var Continued: Boolean);
begin
  CXML.Resume;
  Continued:=True;
end;procedure TCreateFile.ServiceShutdown(Sender: TService);
begin
  if Assigned(CXML) then
  begin
    // The TService must WaitFor the thread to finish (and free it)
    // otherwise the thread is simply killed when the TService ends.
    CXML.Terminate;
    CXML.WaitFor;
    FreeAndNil(CXML);
  end;
end;
//-------------------------------
procedure TGenerate.Execute;
  procedure CreateXMLFile;
  begin
     ...........读取数据库操作,在一般程序中已通过
  end;
const SecBetweenRuns = 60;
var Count: Integer;
begin
  { Place thread code here }
  Count:=0;
  while not Terminated do  // loop around until we should stop
  begin
    Inc(Count);
    if Count >= SecBetweenRuns then
    begin
      Count := 0;
      { place your service code here }
      { this is where the action happens }
      CreateXMLFile;
    end;
    Sleep(1000);
  end;
end;constructor TGenerate.Create(paraConn:TADOConnection);
// Create the thread Suspended so that properties can be set before resuming the thread.
begin
  tConn:=paraConn;
  tConn.Connected:=True;
  qryDoc.Connection:=tConn;
  qryClass.Connection:=tConn;
  FreeOnTerminate := True;
  inherited Create(True);
end;

解决方案 »

  1.   

    CoInitialize(nil); // 在前面加这个,其它的地方,不用加
    tConn.Connected:=True;
      

  2.   

    先谢谢aiirii,改成:
    CoInitialize(nil);
    tConn.Connected:=True;
    后是同样问题,启动时显示“本地计算机上的服务启动又停止了。一些服务自动停止....”
      

  3.   

    QueryServiceStatus()函数怎么取不到服务程序的状态啊,比如取系统服务[Workstation]的状态,老是返回不正确的结果,这是怎么回事啊,是不是有用户权限的问题在里头啊.我可是用administrator登录的系统啊.
      

  4.   

    constructor TGenerate.Create(paraConn:TADOConnection);
    // Create the thread Suspended so that properties can be set before resuming the thread.
    begin
      tConn:=paraConn;这东东能这样赋吗?