Page 1 of 1

Reader.HasRows throws an exception when there is no rows

Posted: Tue 11 Oct 2016 14:42
by PascalD2
Hi,

The HasRows property raises an exception when called on an empty reader...

Code: Select all

            SalesforceCommand cmd = new SalesforceCommand("SELECT ID FROM LENSES", sf.Connection); 
            cmd.Prepare();
            SalesforceDataReader reader = cmd.ExecuteReader();

                if (reader.HasRows)


Type: NullReferenceException
Message: Object reference not set to an instance of an object.


Another question... Should we close the reader once we are done with it... in the sample code of the HasRows property the reader is not closed... Right now I have the same exception raised when I try to close the reader if the reader has no rows.

Thanks

Re: Reader.HasRows throws an exception when there is no rows

Posted: Fri 14 Oct 2016 15:11
by Shalex
PascalD2 wrote:The HasRows property raises an exception when called on an empty reader...
We have reproduced the issue and are investigating it. We will notify you when it is fixed. As a workaround, please use reader.Read():

Code: Select all

    while (reader.Read()) {
        // process a current record
    }
PascalD2 wrote:Another question... Should we close the reader once we are done with it... in the sample code of the HasRows property the reader is not closed... Right now I have the same exception raised when I try to close the reader if the reader has no rows.
While the SalesforceDataReader is in use, the associated SalesforceConnection is busy serving it until you call reader.Close().
We cannot reproduce NullReferenceException when reader.Close() is called on empty (and with records as well) reader with the newest (3.1.121) build of dotConnect for Salesforce. Please upgrade and (if this doesn't help) specify a code snippet for reproducing.