Page 1 of 1
Destroying TOraSession raises exception [ORA-02396]
Posted: Thu 07 Jul 2016 07:53
by m.ghilardi
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.
Re: Destroying TOraSession raises exception [ORA-02396]
Posted: Thu 07 Jul 2016 08:33
by AlexP
Hello,
Please describe in more details what you want to implement. In ODAC, objects are supported in both modes (OCI and Direct)
Re: Destroying TOraSession raises exception [ORA-02396]
Posted: Thu 07 Jul 2016 08:55
by m.ghilardi
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.
Re: Destroying TOraSession raises exception [ORA-02396]
Posted: Thu 07 Jul 2016 09:19
by AlexP
You can use the OnConnectionLost event, to reconnect:
https://www.devart.com/odac/docs/index. ... onlost.htm
Re: Destroying TOraSession raises exception [ORA-02396]
Posted: Thu 07 Jul 2016 10:27
by m.ghilardi
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
Re: Destroying TOraSession raises exception [ORA-02396]
Posted: Thu 07 Jul 2016 11:30
by AlexP
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;
Re: Destroying TOraSession raises exception [ORA-02396]
Posted: Thu 07 Jul 2016 12:28
by m.ghilardi
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?)
}
}
Re: Destroying TOraSession raises exception [ORA-02396]
Posted: Thu 07 Jul 2016 12:43
by AlexP
Glad to see that you have found the solution. If you have any other questions, feel free to contact us