Properly deal with connections in the error state

Closing a cursor does not rollback/clear the error state, so do so
explicitly.