Destroying TOraSession raises exception [ORA-02396]

Discussion of open issues, suggestions and bugs regarding ODAC (Oracle Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
m.ghilardi
Posts: 41
Joined: Thu 13 Mar 2014 11:14

Destroying TOraSession raises exception [ORA-02396]

Post by m.ghilardi » Thu 07 Jul 2016 07:53

How do you destroy an expired session? If a Oracle session expires, when i try to call delete it raises exception!

Code: Select all

ORA-02396:exceeded maximum idle time, please connect again


(which is not supposed to happen in c++)

Right now I have a server that crashes every time a user leaves a client open and times out.

ODAC 9.6.20 for Rad Studio 10. I can't use native connection because I use Oracle Objects. Please help.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Destroying TOraSession raises exception [ORA-02396]

Post by AlexP » Thu 07 Jul 2016 08:33

Hello,

Please describe in more details what you want to implement. In ODAC, objects are supported in both modes (OCI and Direct)

m.ghilardi
Posts: 41
Joined: Thu 13 Mar 2014 11:14

Re: Destroying TOraSession raises exception [ORA-02396]

Post by m.ghilardi » Thu 07 Jul 2016 08:55

Sorry, forget about the last sentence (Oracle Objects have nothing to do with this issue).

My problem is this:
user "scott" has the following profile

Code: Select all

CREATE PROFILE MY_USER_PROFILE LIMIT
  SESSIONS_PER_USER DEFAULT
  CPU_PER_SESSION DEFAULT
  CPU_PER_CALL DEFAULT
  CONNECT_TIME DEFAULT
  IDLE_TIME 10
  LOGICAL_READS_PER_SESSION DEFAULT
  LOGICAL_READS_PER_CALL DEFAULT
  COMPOSITE_LIMIT DEFAULT
  PRIVATE_SGA DEFAULT
  FAILED_LOGIN_ATTEMPTS 10
  PASSWORD_LIFE_TIME 90
  PASSWORD_REUSE_TIME DEFAULT
  PASSWORD_REUSE_MAX DEFAULT
  PASSWORD_LOCK_TIME DEFAULT
  PASSWORD_GRACE_TIME 90
  PASSWORD_VERIFY_FUNCTION DEFAULT;
IDLE_TIME is 10, so if the user is idle for 10 minutes the db session expires.

0) create a TOraSession
1) MySession->Connect(), and then idle (does nothing)
2) After 10 minutes the session exceeds the idle time.....
3) delete MySession>> OraError!

I need a way to destroy an expired session without raising exceptions, because that causes too much problems.

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Destroying TOraSession raises exception [ORA-02396]

Post by AlexP » Thu 07 Jul 2016 09:19

You can use the OnConnectionLost event, to reconnect: https://www.devart.com/odac/docs/index. ... onlost.htm

m.ghilardi
Posts: 41
Joined: Thu 13 Mar 2014 11:14

Re: Destroying TOraSession raises exception [ORA-02396]

Post by m.ghilardi » Thu 07 Jul 2016 10:27

I tried to register an event handler for OnConnectionLost but it doesn't fire in case of TOraSession destruction. By the way, I don't want to reconnect the session in my scenario. Just destroying the TOraSession without exceptions

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Destroying TOraSession raises exception [ORA-02396]

Post by AlexP » Thu 07 Jul 2016 11:30

If you want just to ignore this error, you should use the onError event:

Code: Select all

procedure TForm1.OraSession1Error(Sender: TObject; E: EDAError;
  var Fail: Boolean);
begin
  if EOraError(E).ErrorCode = 2396 then
    Fail := False
  else
    Fail := True;
end;

m.ghilardi
Posts: 41
Joined: Thu 13 Mar 2014 11:14

Re: Destroying TOraSession raises exception [ORA-02396]

Post by m.ghilardi » Thu 07 Jul 2016 12:28

Thanks AlexP, Now I have found a workaround.

In the datamodule I implemented the BeforeDestruction protected member function

Code: Select all

void __fastcall TSessionDataModule::BeforeDestruction()
{
    MySession->Tag = 1;
    TDataModule::BeforeDestruction();
}
then in OnError event handler

Code: Select all

void __fastcall TSessionDataModule::MySessionError(TObject * Sender, EDAError * E, bool & Fail)
{
    if (E->ErrorCode == 2396)
    {
        Fail = MySession->Tag == 0;
        //log something (warning)
    }
    else if (E->IsFatalError())
    {
        Fail = MySession->Tag == 0;
        //log something (ERROR)
    }
   else
    {
        Fail = false;
        //log something (warning?)
    }
   
}

AlexP
Devart Team
Posts: 5530
Joined: Tue 10 Aug 2010 11:35

Re: Destroying TOraSession raises exception [ORA-02396]

Post by AlexP » Thu 07 Jul 2016 12:43

Glad to see that you have found the solution. If you have any other questions, feel free to contact us

Post Reply