Better database query error handling.

When returning due to an error, close the rows object.  Additionally,
when rows.Next returns false, check if it was caused by an error.