我用DELPHI编写了一个NT的服务,且设置为随系统自动启动,使用sqlserver数据库,现在出现一个问题,业务逻辑中要求1分钟触发一次某个事件方法,如果在这期间与SQLSERVER断连,则这个服务还在NT进程中运行,不过那个方法就不再触发,不知为何,请大虾们指教,附代码:procedure TAutoCalcService.ServiceStart(Sender: TService; var Started: Boolean);
begin
  FeeOutHintTh := TFeeOutHintAction.Create(False);
  Started := True;
end;//触发的方法
procedure TFeeOutHintAction.Execute;
Var
  PACard_Type:Integer;
  PACard_Content:String;
begin
Try
  while not Terminated do
  begin
 //取得全局参数
    With CalcData.adsWHParam do
    begin
      Close;
      CommandText:='';
      CommandText:='Select * from NBA_CountWholeParam';
      Open;
      SaleSysInfo.BarAdmin_IP:=FieldByName('BarAdmin_IP').AsString;
      SaleSysInfo.BarAdmin_Port:=FieldByName('BarAdmin_Port').AsInteger;
      SaleSysInfo.FeeOutAction:=FieldByName('FeeOutAction').AsString;
      SaleSysInfo.Prec_Value:=FieldByName('Prec_Value').AsString;
    end;
    With CalcData.adsTMP10 do
    begin
      Close;
      CommandText:='Select * from NBA_OnLineCustomer';
      CommandText:=CommandText+' Where  VIP_Type<>1';  
      Open;
      if CalcData.adsTMP10.RecordCount>0 then
      begin
        First;
        While not eof do
        begin
          if Terminated then Break;
          PACard_Type:=FieldByName('Card_Type').AsInteger;
          PACard_Content:=FieldByName('Card_Content').AsString;
         //调用另一处理方法
          CalcData.CalculateProc(PACard_Type,PACard_Content);
          Next;
        end;
      end;
    end;
    Sleep(60000);
  end;
Except
  on E: Exception do
   if (E.Message='连接失败')
   or (E.Message='[DBNETLIB][ConnectionOpen (Connect()).]SQL Server 不存在或拒绝访问。') then
End;
end;

解决方案 »

  1.   

    哪个方法不触发了?而且你用TRY保护了,当连接失败后,就不能执行下面的操作了,还有建议你在操作数据库的时候加上Synchronize和CoInitializeEx(nil,COINIT_MULTITHREADED);
      

  2.   

    TFeeOutHintAction.Execute
    不执行了,或者说服务不运行了。
    还有请明确说明用
    Synchronize和CoInitializeEx(nil,COINIT_MULTITHREADED);
    的好处以及功能。
      

  3.   

    没具体看你的内容,但是估计是逻辑结构搞错了,估计你的意思应该是while not termianted do
    begin
      try
        ...
      except
        ...
      end;
    end;而不是
    try
      while not terminated do
      begin
        ...
      end;
    except 
      ...
    end;
      

  4.   

    强烈建议使用C#写application service