free all handles when disconnecting
Posted: Tue 02 Nov 2010 15:56
Hello!
I have a problem using dbexpoda.dll Version 4.20.0.8. The problem also remains with current trial version 4.70.0.22.
I' am using Borland C++ Builder Version 6 and connect (for the test) to an "Oracle9i Release 9.2.0.8.0 - Production" database.
The database driver is used by a report generation application. It can be used as system service or as desktop application. (each running on Windows XP Professional, 32bit)
When I run it as system service I experience the problem, when I run it as desktop I DON'T experience the problem.
The problem origination:
The application often reconnects. (adjustable, but typically in a 5 seconds interval)
Thererfore each time I close the connection and then open a new connection (Tests have shown, that whether I reuse the old TSQLConnection object or not, does not matter.).
This behaviour is desired since the application design supports only a single database connection.
(It does not make sense to reconnect to the same database. But typically there are 3 database users (connect to USER1, close USER1, connect to USER2, close USER2, connect to USER3, close USER3, wait 5 seconds, connect to USER1, and so on).)
The resulting problem:
Every time a new connection is opened, (Connected=true), 11 handles are reserved.
Every time a connection is closed (Close()), 9 handles are freed.
>>>> The is a leak of 2 handles every time I reconnect.
#include
#include
#include
//---------------------------------------------------------------------------
// DBExpress:
#include
#include
#include
// SQLClientDataset
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // Von der IDE verwaltete Komponenten
void __fastcall FormActivate(TObject *Sender);
private: // Anwender-Deklarationen
TSQLConnection* myDatabase;
public: // Anwender-Deklarationen
__fastcall TForm1(TComponent* Owner);
void __fastcall TimerEvent( TObject* Sender );
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
THE C PLUS PLUS FILE
-------------------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
// I know the timer and the lastly opened connection should be disposed when the application is closed, but it is not relevant for this example.
TTimer* timer = new TTimer( NULL );
this->myDatabase = NULL;
timer->OnTimer = TimerEvent;
timer->Interval = 5000;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TimerEvent( TObject* Sender )
{
// (plus 11 handles minus 9 handles) is plus 2 handles for each timer event
// disconnect
if( this->myDatabase != NULL )
{
// following line: setting Connected to false does not help
//myDatabase->Connected = false;
// following line: closing frees 9 handles
myDatabase->Close();
// following two lines: disposing the connection does not help
//delete myDatabase;
//this->myDatabase = NULL;
}
// connect
if( myDatabase == NULL )
{
myDatabase = new TSQLConnection( NULL );
myDatabase->LoginPrompt = false;
}
try
{
String inAlias = "DATAOBJECTS_ORC1";
String inUserName = "USER1";
String inPassWord = "USER1";
String driverName, vendorLib, getDriverFunc, libraryName, dataBase;
driverName = "Oracle (Core Lab)";
vendorLib = "oci.dll";
libraryName = "dbexpoda.dll";
getDriverFunc = "getSQLDriverORA";
dataBase = inAlias;
myDatabase->DriverName = driverName;
myDatabase->VendorLib = vendorLib;
myDatabase->LibraryName = libraryName;
myDatabase->GetDriverFunc = getDriverFunc;
myDatabase->Params->Clear();
myDatabase->Params->Add( "Database=" + dataBase );
myDatabase->Params->Add( "User_Name=" + inUserName );
myDatabase->Params->Add( "Password=" + inPassWord );
// following line: connecting requires 11 handles
myDatabase->Connected = true;
}
catch(Exception &e)
{
int debug2 = 0;
debug2++;
}
int debug3 = 0;
debug3++;
}
//---------------------------------------------------------------------------
Any help or hint is appreciated. Am I doing anything wrong? (Possibly it is not an issue of the devart driver, since I have experienced the same when using the Borland (dbexpora.dll) driver.)
I have a problem using dbexpoda.dll Version 4.20.0.8. The problem also remains with current trial version 4.70.0.22.
I' am using Borland C++ Builder Version 6 and connect (for the test) to an "Oracle9i Release 9.2.0.8.0 - Production" database.
The database driver is used by a report generation application. It can be used as system service or as desktop application. (each running on Windows XP Professional, 32bit)
When I run it as system service I experience the problem, when I run it as desktop I DON'T experience the problem.
The problem origination:
The application often reconnects. (adjustable, but typically in a 5 seconds interval)
Thererfore each time I close the connection and then open a new connection (Tests have shown, that whether I reuse the old TSQLConnection object or not, does not matter.).
This behaviour is desired since the application design supports only a single database connection.
(It does not make sense to reconnect to the same database. But typically there are 3 database users (connect to USER1, close USER1, connect to USER2, close USER2, connect to USER3, close USER3, wait 5 seconds, connect to USER1, and so on).)
The resulting problem:
Every time a new connection is opened, (Connected=true), 11 handles are reserved.
Every time a connection is closed (Close()), 9 handles are freed.
>>>> The is a leak of 2 handles every time I reconnect.
#include
#include
#include
//---------------------------------------------------------------------------
// DBExpress:
#include
#include
#include
// SQLClientDataset
#include
#include
#include
#include
#include
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // Von der IDE verwaltete Komponenten
void __fastcall FormActivate(TObject *Sender);
private: // Anwender-Deklarationen
TSQLConnection* myDatabase;
public: // Anwender-Deklarationen
__fastcall TForm1(TComponent* Owner);
void __fastcall TimerEvent( TObject* Sender );
};
//---------------------------------------------------------------------------
extern PACKAGE TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
THE C PLUS PLUS FILE
-------------------------------------------------------------------------------------
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormActivate(TObject *Sender)
{
// I know the timer and the lastly opened connection should be disposed when the application is closed, but it is not relevant for this example.
TTimer* timer = new TTimer( NULL );
this->myDatabase = NULL;
timer->OnTimer = TimerEvent;
timer->Interval = 5000;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TimerEvent( TObject* Sender )
{
// (plus 11 handles minus 9 handles) is plus 2 handles for each timer event
// disconnect
if( this->myDatabase != NULL )
{
// following line: setting Connected to false does not help
//myDatabase->Connected = false;
// following line: closing frees 9 handles
myDatabase->Close();
// following two lines: disposing the connection does not help
//delete myDatabase;
//this->myDatabase = NULL;
}
// connect
if( myDatabase == NULL )
{
myDatabase = new TSQLConnection( NULL );
myDatabase->LoginPrompt = false;
}
try
{
String inAlias = "DATAOBJECTS_ORC1";
String inUserName = "USER1";
String inPassWord = "USER1";
String driverName, vendorLib, getDriverFunc, libraryName, dataBase;
driverName = "Oracle (Core Lab)";
vendorLib = "oci.dll";
libraryName = "dbexpoda.dll";
getDriverFunc = "getSQLDriverORA";
dataBase = inAlias;
myDatabase->DriverName = driverName;
myDatabase->VendorLib = vendorLib;
myDatabase->LibraryName = libraryName;
myDatabase->GetDriverFunc = getDriverFunc;
myDatabase->Params->Clear();
myDatabase->Params->Add( "Database=" + dataBase );
myDatabase->Params->Add( "User_Name=" + inUserName );
myDatabase->Params->Add( "Password=" + inPassWord );
// following line: connecting requires 11 handles
myDatabase->Connected = true;
}
catch(Exception &e)
{
int debug2 = 0;
debug2++;
}
int debug3 = 0;
debug3++;
}
//---------------------------------------------------------------------------
Any help or hint is appreciated. Am I doing anything wrong? (Possibly it is not an issue of the devart driver, since I have experienced the same when using the Borland (dbexpora.dll) driver.)