我用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;
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;
解决方案 »
- 求助:自定义过程时间,调用时出错?
- 请帮忙推荐几款较好的IC卡考勤机
- 怎樣在checklistbox里show ini文件里的關鍵字!!!
- 高分求助Delphi2005正式版本的下载 (50)
- 错误提示:'array type requied'怎么回事呢?
- 请问李维的《D5分布式多层应用 系统篇》中的一个问题(或在一个DataSet中显示另一个DataSet中的一个TDataSet类型字段)。
- 如何使用locate?
- Delphi如何做到监视一个WEB窗口的运行,并能截取WEB窗口发往网站的消息?在线等候...
- 请问DBF数据库(Base III)要求一个字段中输入(年-月-日-时-分),该字段类型应为什么?
- 把记录的字段写入Excel里?
- combobox如何设置默认项?
- 获取WebBrowser当前点击的连接的url地址。。。。(搜索了很多,都是写列举所有连接,而没有当前连接)
不执行了,或者说服务不运行了。
还有请明确说明用
Synchronize和CoInitializeEx(nil,COINIT_MULTITHREADED);
的好处以及功能。
begin
try
...
except
...
end;
end;而不是
try
while not terminated do
begin
...
end;
except
...
end;