TOraAlerter always raises Exception with Message Dialog in console application with Delphi 7

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
ASIT
Posts: 4
Joined: Fri 01 Apr 2005 11:18

TOraAlerter always raises Exception with Message Dialog in console application with Delphi 7

Post by ASIT » Fri 01 Apr 2005 11:30

Hello,

I am developing a console application which has to reconnect to the oracle database if the connection lost.
But the TOraAlerter always raises an exception with an message dialog and don't use the OnError event of the TOraSession.
What can I do to prevent the TOraAlerter from raising the exception and use the OnError Event from the TOraSession?

I have a small test console application for TOraAlerter:

Code: Select all

program OraAlerterTest;

//------------------------------------------------------------------------------

{$APPTYPE CONSOLE}

//------------------------------------------------------------------------------

uses
  SysUtils, Forms, DB, DBAccess, Ora, OraAlerter;

//------------------------------------------------------------------------------

type
  TTestClass = class(TObject)
  private
    FOraAlerter: TOraAlerter;
    FOraSession: TOraSession;
    procedure DoAfterConnect(Sender: TObject);
    procedure DoAfterDisconnect(Sender: TObject);
    procedure DoOnError(Sender: TObject; E: EDAError; var Fail: Boolean);
    procedure DoOnEvent(Sender: TObject; Event, Message: string);
  public
    constructor Create;
    destructor Destroy; override;
    procedure MainLoop;
  end;

//------------------------------------------------------------------------------

constructor TTestClass.Create;
begin
  inherited;

  try
    Self.FOraSession:=TOraSession.Create(NIL);
    Self.FOraSession.Username:='scott';
    Self.FOraSession.Password:='tiger';
    Self.FOraSession.Server:='PROD.LOCAL';
    Self.FOraSession.AfterConnect:=Self.DoAfterConnect;
    Self.FOraSession.AfterDisconnect:=Self.DoAfterDisconnect;
    Self.FOraSession.OnError:=Self.DoOnError;

    Self.FOraAlerter:=TOraAlerter.Create(Self.FOraSession);
    Self.FOraAlerter.Session:=Self.FOraSession;
    Self.FOraAlerter.Events:='TEST_PIPE';
    Self.FOraAlerter.EventType:=etPipe;
    Self.FOraAlerter.TimeOut:=-1;
    Self.FOraAlerter.OnEvent:=Self.DoOnEvent;

    WriteLn('Connecting...');
    Self.FOraSession.Connect;
    Self.FOraAlerter.Active:=True;
  except
    on E: Exception do
    begin
      WriteLn('Exception Create: '+E.Message);
    end;
  end;
end;

//------------------------------------------------------------------------------

destructor TTestClass.Destroy;
begin
  try
    WriteLn('Disconnecting...');
    Self.FOraAlerter.Active:=False;
    Self.FOraSession.Disconnect;
  finally
    FreeAndNil(Self.FOraAlerter);
    FreeAndNil(Self.FOraSession);
  end;

  inherited;
end;

//------------------------------------------------------------------------------

procedure TTestClass.DoAfterConnect(Sender: TObject);
begin
  WriteLn('Connected');
end;

//------------------------------------------------------------------------------

procedure TTestClass.DoAfterDisconnect(Sender: TObject);
begin
  WriteLn('Disconnected');
end;

//------------------------------------------------------------------------------

procedure TTestClass.DoOnError(Sender: TObject; E: EDAError; var Fail: Boolean);
begin
  WriteLn('Error');
end;

//------------------------------------------------------------------------------

procedure TTestClass.DoOnEvent(Sender: TObject; Event, Message: string);
begin
  WriteLn('PipeMsg="'+Message+'"');
end;

//------------------------------------------------------------------------------

procedure TTestClass.MainLoop;
begin
  repeat
    Application.ProcessMessages;
    Sleep(1);
  until FileExists(ChangeFileExt(Application.ExeName,'.end'));
end;


//------------------------------------------------------------------------------
// MAIN
//------------------------------------------------------------------------------
var
  test: TTestClass;

begin
  try
    WriteLn('OraAlerter-Test v1.0');
    test:=TTestClass.Create;
    test.MainLoop();
  finally
    FreeAndNil(test);
  end;
end.


ODAC Net 5.50.0.15 for Delphi 7
Oracle 9i R2 v9.2.0.1.0

Thanks for your help.

Bye
Andreas

ASIT
Posts: 4
Joined: Fri 01 Apr 2005 11:18

I forgot ...

Post by ASIT » Fri 01 Apr 2005 11:32

Hi,

:oops: I forgot something:
TOraAlerter raises the exception if I shutdown the Oracle instance i.e. with "shutdown abort".

Bye
Andreas

ASIT
Posts: 4
Joined: Fri 01 Apr 2005 11:18

Also OraSession.Connected is true if I shutdown the database

Post by ASIT » Fri 01 Apr 2005 12:07

Hi,

another problem:
After shutdown the Oracle Database the property Connected of the TOraSession is always true.

Any idea?

Bye
Andreas

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Mon 04 Apr 2005 14:23

OraSession.OnError event handles Oracle errors only, exception that raised when you shutdown server is not Oracle error so it couldn't be handled by OraSession.OnError event. We will change exception type to EDatabaseError in the next ODAC build to get you an opportunity to catch and identify this exception.

As to your question about Connected property while Oracle server is shouting down - ODAC doesn't ping server during application work to avoid excessive traffic so it can't determine when connection with Oracle server is lost. This situation will be detected with the fist attempt to access Oracle server.

ASIT
Posts: 4
Joined: Fri 01 Apr 2005 11:18

Post by ASIT » Wed 06 Apr 2005 13:45

Hello,

thanks for your answer.

I think, that the shutdown of the Oracle Instance (with shutdown abort in sqlplus) is an Oracle Error because I get the error message: ORA-03113 end-of-file on communication channel.

If I shutdown the Oracle Instance (not the server) with "shutdown abort" in sqlplus the test application always raises an exception with a message dialog. It is not possible for me to catch the exception and handle it by my self.

I also bought the ODAC Professional version with the source code but I was not able to find how I can make this.

I hope you can help me.

Bye
Andreas

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Wed 06 Apr 2005 15:18

Sorry for misunderstanding, we reproduced your problem and fixed it. This fix will be included in the next ODAC build.

keckhard
Posts: 12
Joined: Fri 08 Apr 2005 09:18

When will the next version of odac be available?

Post by keckhard » Fri 08 Apr 2005 09:37

Hi,

we have exact the same problem. When data is inserted in a Oracle-table a trigger is fired which is raising an alert. My Delphi application is waiting for this alert, and should do something when it receives it. If the database goes down for any reason (instance crash, session crash, maintainance, ....), the application should try to reconnect to the database till the database is available again. This works fine for all other classes, except the TOraAlerter Class. So my short question is, when will this ODAC version with the fix described below be available?

Suggestion: A Method OnError similar to OnEvent, for customized Exception handling would be great!

br, klaus.

Alex
Posts: 655
Joined: Mon 08 Nov 2004 08:39

Post by Alex » Mon 11 Apr 2005 06:40

The new ODAC build will be available in about two weeks.

Post Reply