Reopen the database only when we need it again