[Interest] Long running application with database connection

André Somers andre at familiesomers.nl
Thu Oct 10 08:58:06 CEST 2013

Op 10-10-2013 8:51, Marc Schmitzer schreef:
> On 10/09/2013 04:46 PM, S R wrote:
>> In a similar situation, if I recall correctly, we elected to open the
>> database connection each time we needed it.  Through testing we found
>> that connection pooling in the the underlying infrastructure (windows,
>> using oracle and ms sqlserver) worked well.  The reconnection cost was
>> usually trivial compared with the actual query especially if the
>> connection was recently used; the resulting code was simpler/cleaner;
>> and the approach seemed robust to lots of other reasons (not just idle
>> time) that the connection might drop.  I do recall that it was hard to
>> test well.
> I considered that as well, but I see the problem that some subroutine
> that interacts with the database cannot know whether something higher up
> the call stack is also, in which case closing the connection would leave
> the higher stack frame with an invalid connection.
> Of course you could do something more involved like "only close the
> connection if you opened it",
That would not even help, I think
> but I'd rather avoid fixing up every
> single database access.
> I still don't know whether keeping the connection open for a long time
> is somehow a bad idea. But on the other hand, the mysqld wait_timeout
> can be configured to up to a year, so it can't be that bad.
It sounds to me like you have your database access too spread out in 
your application. I really try to confine access to resources into 
specialized (groups of) classes to manage that resource. That works well 
for databases, and makes it that much easier to manage issues like these.


You like Qt?
I am looking for collegues to join me at i-Optics!

More information about the Interest mailing list