[Interest] Long running application with database connection

Marc Schmitzer marc.schmitzer at richard-wolf.com
Thu Oct 10 08:51:53 CEST 2013

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", 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.

Mit freundlichen Gruessen / Best regards

Marc Schmitzer

SW-Entwicklung ESWL / ESWT
Software development ESWL / ESWT


Richard Wolf GmbH

Pforzheimer Strasse 32

75438 Knittlingen

Tel.:         +49 7043 35-1107
Fax:          +49 7043 35-1255
Email:        marc.schmitzer at richard-wolf.com
Web:          http://www.richard-wolf.com

Richard Wolf GmbH, Pforzheimer Strasse 32, 75438 Knittlingen
Managing Directors: Siegfried Karst, Juergen Pfab, Juergen Steinbeck. Trade Register: Mannheim HRB 510031
Richard Wolf GmbH routinely monitors the content of e-mail sent and received via its network for the purposes of ensuring compliance with its policies and procedures. Richard Wolf GmbH is not responsible for any changes made to the message after it has been sent. Where opinions are expressed, they are not necessarily those of Richard Wolf GmbH. This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to which they are addressed. If you are not the intended addressee, or the person responsible for delivering it to them, you may not copy, forward, disclose, or otherwise use it or any part of it in any way. To do so may be unlawful. If you receive this e-mail by mistake, please advise the sender immediately.

More information about the Interest mailing list