How close the connection

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
e.arlati

How close the connection

Post by e.arlati » Fri 18 Feb 2005 13:23

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

Ikar
Posts: 1693
Joined: Thu 28 Oct 2004 13:56

Post by Ikar » Mon 21 Feb 2005 10:14

Are you sure that TDataModule_PMV::RemoveMyConnection is called?
Do you use MyConnection.Pooling?

e.arlati

Post by e.arlati » Mon 21 Feb 2005 10:20

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

Post Reply