Page 1 of 1

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

Posted: Fri 01 Apr 2005 11:30
by ASIT
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

I forgot ...

Posted: Fri 01 Apr 2005 11:32
by ASIT
Hi,

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

Bye
Andreas

Also OraSession.Connected is true if I shutdown the database

Posted: Fri 01 Apr 2005 12:07
by ASIT
Hi,

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

Any idea?

Bye
Andreas

Posted: Mon 04 Apr 2005 14:23
by Alex
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.

Posted: Wed 06 Apr 2005 13:45
by ASIT
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

Posted: Wed 06 Apr 2005 15:18
by Alex
Sorry for misunderstanding, we reproduced your problem and fixed it. This fix will be included in the next ODAC build.

When will the next version of odac be available?

Posted: Fri 08 Apr 2005 09:37
by keckhard
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.

Posted: Mon 11 Apr 2005 06:40
by Alex
The new ODAC build will be available in about two weeks.