ensure database is closed when it should be