persistency bug fix

use only one DB connection, 
wait until it is established and allow to disconnect when done (otherwise application never terminates)