reconnecting to database in case of failure