Fixed database error handling.