fixed problem when a query raised a database error