Page 1 of 1

How close the connection

Posted: Fri 18 Feb 2005 13:23
by e.arlati
I get an application with several thread , with each thread using it's own connection.
What I mean is that the thread create a connection at the beginning and close and detroy it before it close.

Under some circustances some of these threads close itself and reopen after few minutes ( for example 60 secs. ).
When this appened also if the connection is closed , it is still registered as active by mysql.
So I got that each time a new thread is started a new connection is added to the list of mysql connection.
When the thread died , mysql keep a reference to an idle connection until the wait_timeout expiration time.

So I must keep the value of wait_timeout lower , ie. = 120, while the preferred value should higher that this value.

There are some way to shorten the timeout for removing the connections without interfere with the timeout used for still active connection ?


I'm using mdac with c++buider 6 and the way I create and destroy the connection are showed belowe:

TMyConnection * __fastcall TDataModule_PMV::NewMyConnection(String hostName)
{
String strmsg;
TMyConnection * myConn = 0;
myConn = new TMyConnection( NULL );

myConn->Server = hostName;
myConn->Database = "mydatabaser";
myConn->Username = "my_user";
myConn->Password = "my_password";
myConn->LoginPrompt = false;
myConn->Connected = true;

return myConn;
}


/********************************************************/
void __fastcall TDataModule_PMV::RemoveMyConnection(TMyConnection * dbConn)
{
if( dbConn )
{
dbConn->Connected = false;
delete dbConn;
dbConn = 0;
}
}



Regards, Enzo Arlati

Posted: Mon 21 Feb 2005 10:14
by Ikar
Are you sure that TDataModule_PMV::RemoveMyConnection is called?
Do you use MyConnection.Pooling?

Posted: Mon 21 Feb 2005 10:20
by e.arlati
You're are right.
It is a my huge mistake, I reassigned the thread variable before deleting it , so also the TDataModule_PMV::RemoveMyConnection where no more called.

Regards, Enzo