Implemented retry handling when attempting to close the database.