bz19889: Fixes for database error handling