私は Delphi 6 で作られた Windows サービスを持っています。これは進行状況の openge データベースに接続し、情報を 1 日 1 回 MySQL データベースに転送します。問題は、サービスを開始すると正常に動作することですが、進行状況データベースを更新すると、翌日、サービスがまだ最初の値 (同じ値) を表示していることです。データベースイメージがあり、更新されないようです。サービスを再起動すると、新しい値が取得されますが、翌日には同じことが起こります。
データベース接続には TDatabase クラスを使用します。誰でもこれを修正する方法を知っていますか?
これはコードです:
unit svcMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, SvcMgr, Dialogs,
ExtCtrls, AppEvnts, DateUtils, inifiles;
type
TsvcAgraria = class(TService)
timAcao: TTimer;
procedure timAcaoTimer(Sender: TObject);
procedure ServicePause(Sender: TService; var Paused: Boolean);
procedure ServiceStart(Sender: TService; var Started: Boolean);
procedure ServiceStop(Sender: TService; var Stopped: Boolean);
procedure ServiceContinue(Sender: TService; var Continued: Boolean);
function RightPad(S: string; Ch: Char; Len: Integer): string;
private
{ Private declarations }
procedure Gera_log(ctipo,msgtxt:string);
procedure Replica_Dados();
procedure Verifica_Ini();
public
function GetServiceController: TServiceController; override;
{ Public declarations }
end;
var
svcAgraria: TsvcAgraria;
lsup1,lsup2,lsupexc,ltudook:boolean;
cont_registros:integer;
teste,loteini,lotefim,tLooping:string;
implementation
uses UdtmRamal;
{$R *.DFM}
procedure ServiceController(CtrlCode: DWord); stdcall;
begin
svcAgraria.Controller(CtrlCode);
end;
function TsvcAgraria.GetServiceController: TServiceController;
begin
Result := ServiceController;
end;
procedure TsvcAgraria.ServiceStart(Sender: TService; var Started: Boolean);
begin
Gera_Log('INFO','Iniciado o Serviço Windows para Replicação de Ramais.');
timAcao.Enabled := Started;
end;
procedure TsvcAgraria.ServiceStop(Sender: TService; var Stopped: Boolean);
begin
timAcao.Enabled := not(Stopped);
Gera_Log('INFO','Finalizado o Serviço Windows para Replicação de Ramais.');
end;
procedure TsvcAgraria.ServicePause(Sender: TService; var Paused: Boolean);
begin
timAcao.Enabled := not(Paused);
Gera_Log('INFO','Serviço Pausado.');
end;
procedure TsvcAgraria.ServiceContinue(Sender: TService;
var Continued: Boolean);
begin
timAcao.Enabled := Continued;
Gera_Log('INFO','Serviço em Execução.');
end;
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
procedure TsvcAgraria.timAcaoTimer(Sender: TObject);
var tagora:string;
begin
Verifica_Ini();
tagora := RightPad(IntToStr(HourOf(Now)), '0', 2) + ':' + RightPad(IntToStr(MinuteOf(Now)), '0', 2);
//Gera_Log('INFO','Valores à comparar: var "' + tagora + '", ini "' + tLooping + '".');
if (tLooping = tagora) then
begin
Replica_Dados();
end;
end;
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
procedure TsvcAgraria.Replica_Dados();
var
_validaprof:integer;
begin
Gera_Log('INFO','--- Iniciando a Replicação de Dados para a Intranet...');
/////////////////////////////////////////////////
try
dtmAtualizaRamal.DbMyRamal.Connected:=true;
dtmAtualizaRamal.ConectDBHR.Connected:=true;
if (dtmAtualizaRamal.ConectDBHR.Connected and dtmAtualizaRamal.DbMyRamal.Connected) then
begin
/* BUSINESS LOGIC */
end;
except
on E: Exception do Gera_Log('ERRO',E.Message);
end;
Gera_Log('INFO','--- Desconectar Banco.');
dtmAtualizaRamal.DbMyRamal.Connected:=false;
dtmAtualizaRamal.ConectDBHR.Connected:=false;
Gera_Log('INFO','--- Final da Replicação de Dados para a Intranet.');
end;
function TsvcAgraria.RightPad(S: string; Ch: Char; Len: Integer): string;
var
RestLen: Integer;
begin
Result := S;
RestLen := Len - Length(s);
if RestLen < 1 then Exit;
Result := StringOfChar(Ch, RestLen) + S;
end;
procedure TsvcAgraria.Gera_log(ctipo,msgtxt:string);
var
LogFileName,LogData:string;
LogFile:TextFile;
begin
LogFileName := 'c:\datasul\temp\scvRamais.log.txt';
AssignFile(LogFile, LogFileName);
//either create an error log file, or append to an existing one
if FileExists(LogFileName) then
Append(LogFile)
else
Rewrite(LogFile);
try
//add the current date/time and the exception message to the log
LogData := Format('%s : %s : %s',[DateTimeToStr(Now),ctipo,msgtxt]) ;
WriteLn(LogFile,LogData) ;
finally
CloseFile(LogFile);
end;
end;
end.