Re: Design Pattern to keep a connection opened?

Bruce Johnson <[email protected]>
Newsgroups gmane.comp.lang.perl.modules.dbi.general
Message-ID <[email protected]>
On Nov 5, 2011, at 3:57 PM, Brandon Phelps wrote:

> Can anyone point me in the right direction for keeping a connection to my database opened?
> 
> The script I need to write will run 24/7 executing a postgresql stored procedure which inserts records into the database.  The problem I think I might have is using a standard procedural syntax of:
> 
> Open connection
> Loop
>    Call stored procedure/function
> 
> ...if my connection gets interrupted somewhere during the loop any subsequent iterations will obviously fail, so I need a way of reconnecting to the database should the need arise.  Basically something like this (I'm just not sure how to actually code this):

Why not just open a database connection, run the procedure and close it again? :

Loop
	open db
	run proc
	close db
End loop

?
If the connection is staying open long enough to get stale and be disconnected, then you shouldn't be running into timing issues.



-- 
Bruce Johnson
University of Arizona
College of Pharmacy
Information Technology Group

Institutions do not have opinions, merely customs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.