C
childe
Unregistered / Unconfirmed
GUEST, unregistred user!
我写了一个程序,定时访问Oracle,从其中一个数据表定时取数后生成文本文件保存。
但当程序运行大约四小时后,程序本身不响应,再也连接不上Oracle,取不到数据。
并且在程序的运行目录下生成一个名为sqlnet的文件。
请各位高手指点,谢谢。
程序源码如下:
unit Oracle;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
ADOQuery: TADOQuery;
btnSelectData: TButton;
Timer1: TTimer;
btnStopSelect: TButton;
procedure btnSelectDataClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure btnStopSelectClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnSelectDataClick(Sender: TObject);
begin
Timer1.Interval := 30000;
Timer1.Enabled := true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
OutPutFileName: string;
sSQL: string;
AFile: TextFile;
fValue: real;
sPointName: string;
nRecCount: integer;
sResult: string;
begin
sResult := '';
with ADOQuery do
begin
Close();
ConnectionString := 'Provider=MSDASQL.1;Password=ch;';
ConnectionString := ConnectionString + 'Persist Security Info=True;User ID=cc;';
ConnectionString := ConnectionString + 'Data Source=ORA;Mode=ReadWrite';
SQL.Clear();
sSQL := 'select PointName,DataValue from ucet_parm where datavalue > -1000000';
SQL.Add(sSQL);
Open();
if RecordCount <> 0 then
begin
ADOQuery.First();
for nRecCount:=1 to RecordCount do
begin
fValue := Fields[1].Value;
sPointName := Fields[0].Value;
sResult := sResult + IntToStr(nRecCount) + ':' + chr(9);
sResult := sResult + sPointName + chr(9);
sResult := sResult + FloatToStr(fValue) + chr(13) + chr(10);
Next();
end;
end;
end;
Memo1.Lines.Clear();
Memo1.Lines.Add(sResult);
GetDir(0,OutPutFileName);
OutPutFileName := OutPutFileName + '/realtimedata/';
setcurrentdir(outputfilename);
outputfilename := FormatDateTime('yyyymmddhhnnss".txt"',Now);
Assignfile(AFile,OutputFileName);
Rewrite(AFile);
Write(AFile,sResult);
CloseFile(AFile);
end;
procedure TForm1.btnStopSelectClick(Sender: TObject);
begin
Timer1.Enabled := false;
end;
end.
但当程序运行大约四小时后,程序本身不响应,再也连接不上Oracle,取不到数据。
并且在程序的运行目录下生成一个名为sqlnet的文件。
请各位高手指点,谢谢。
程序源码如下:
unit Oracle;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, DB, ADODB, ExtCtrls, ComCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
ADOQuery: TADOQuery;
btnSelectData: TButton;
Timer1: TTimer;
btnStopSelect: TButton;
procedure btnSelectDataClick(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure btnStopSelectClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.btnSelectDataClick(Sender: TObject);
begin
Timer1.Interval := 30000;
Timer1.Enabled := true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
OutPutFileName: string;
sSQL: string;
AFile: TextFile;
fValue: real;
sPointName: string;
nRecCount: integer;
sResult: string;
begin
sResult := '';
with ADOQuery do
begin
Close();
ConnectionString := 'Provider=MSDASQL.1;Password=ch;';
ConnectionString := ConnectionString + 'Persist Security Info=True;User ID=cc;';
ConnectionString := ConnectionString + 'Data Source=ORA;Mode=ReadWrite';
SQL.Clear();
sSQL := 'select PointName,DataValue from ucet_parm where datavalue > -1000000';
SQL.Add(sSQL);
Open();
if RecordCount <> 0 then
begin
ADOQuery.First();
for nRecCount:=1 to RecordCount do
begin
fValue := Fields[1].Value;
sPointName := Fields[0].Value;
sResult := sResult + IntToStr(nRecCount) + ':' + chr(9);
sResult := sResult + sPointName + chr(9);
sResult := sResult + FloatToStr(fValue) + chr(13) + chr(10);
Next();
end;
end;
end;
Memo1.Lines.Clear();
Memo1.Lines.Add(sResult);
GetDir(0,OutPutFileName);
OutPutFileName := OutPutFileName + '/realtimedata/';
setcurrentdir(outputfilename);
outputfilename := FormatDateTime('yyyymmddhhnnss".txt"',Now);
Assignfile(AFile,OutputFileName);
Rewrite(AFile);
Write(AFile,sResult);
CloseFile(AFile);
end;
procedure TForm1.btnStopSelectClick(Sender: TObject);
begin
Timer1.Enabled := false;
end;
end.