Ensure 'db' is not null