访问Oracle数据库的问题(200分)

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.
 
用ado连接oracle不如用bde,你用bde试试,另外,系统的资源你也看看.
 
我是用bde连接oracle 的, 工作的很好。但当网络经常断线时,客户端程序会死,这与
网络有关。
 
数据库应该在一定时间后中断没有工作的连接,你看看是不是这样的问题
 
你可以看看sqlnet中有什么?那是oracle的客户端生成的错误信息。
本人用ADO连接oracle的程序情况与你类似,单数月的运行没有问题
 
几点建议:
1、 查询完毕,关掉数据库连接;
2、 防止时钟重入
procedure Timer1Timer();
begin
Timer1.Enabled := False;
try
……
finally
Timer1.Enable := True;
end;
end;
3、 研究sqlnet文件中的信息
 
谢谢各位!
1、我想使用BDE写代码,但我没有使用过,不知道能否提供参考代码?
2、我也非常怀疑数据库是否每隔一定的时间就断开连接?但不知道Oracle中是怎样设置的?
能否给我一些信息?
3、我将SQLNET中的信息贴在下面,请帮忙分析。谢谢。
***********************************************************************
Fatal OSN connect error 12154, connecting to:
1.1.1.1

VERSION INFORMATION:
TNS for 32-bit Windows: Version 2.3.4.0.0 - Production
Time: 01-SEP-02 16:24:05
Tracing not turned on.


***********************************************************************
Fatal OSN connect error 12547, connecting to:
(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=BEQ)(PROGRAM=oracle80)(ARGV0=oracle80ORCL)(ARGS='(DESCRIPTION=(LOCAL=YES)(ADDRESS=(PROTOCOL=beq)))')))(CONNECT_DATA=(SID=ORCL)(CID=(PROGRAM=Delphi32.exe)(HOST=ORA-YXC)(USER=Administrator))))

VERSION INFORMATION:
TNS for 32-bit Windows: Version 2.3.4.0.0 - Production
Oracle Bequeath NT Protocol Adapter for 32-bit Windows: Version 2.3.4.0.0 - Production
Time: 01-SEP-02 16:24:05
Tracing not turned on.
Tns error struct:
nr err code: 12206
TNS-12206: TNS:在进行导航器时接收到 TNS 错误
ns main err code: 12547
TNS-12547: TNS:丢失连接
ns secondary err code: 12560
nt main err code: 517
TNS-00517: 失去的连接
nt secondary err code: 0
nt OS err code: 0
 
我现在的目标系统是一个性能非常差的系统:Oracle 7.x/VMS.
 
网络状态不好的缘故导致你的应用程序死机。
一定要按照tanxh的第二个建议来修改你的源代码!

BDE访问ORACLE关键不在于程序代码,而在于BDE的配置。
这个东东比较烦人,主要是两个DLL文件名你可能需要调整。
你可以自己先试试,然后再到论坛上来提问。
 
谢谢诸位!
 
谢谢大家的热情支持。
因为我刚学习使用Delphi不久,对BDE的配置和使用一点概念都没有。能够介绍一二?
我采纳tanxh的建议修改程序后,运行的状况没有改变。
好像是oracle系统对用户的访问作了一些限制,每当我访问一定次数之后,tns进程被保留,
使用oracle的客户端工具sql plus连接时,oracle提示我更换其他帐户登录。
我不知道这是为什么?希望oracle高手能够给予一些提示。
谢谢。
 
在timer1timer的最后,关闭adoquery。
delphi的demo中就有如何使用BDE的例子,你可以去参考。
不知道你对oracle的了解有多少,有些oracle方面的问题不是一两句话能说得清的。
你还是先去看看delphi方面的书吧。
oracle提示让你更换登录帐户,说明当前所使用的登录帐户已经有太多的活动连接。
不能再增加了。

TNS-00517 Lost contact
Cause: Partner has unexpectedly gone away.
Action: Investigate partner application for abnormal termination.

 
to armyjiang:
“当前所使用的登录帐户已经有太多的活动连接”,我能够对活动连接进行控制吗?比如说,断开。
 
顶部