automatically reconnect to database if necessary