Beginning work on query, handle database errors.