Reader.HasRows throws an exception when there is no rows

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Cloud Applications
Post Reply
PascalD2
Posts: 9
Joined: Wed 12 Jan 2011 03:48

Reader.HasRows throws an exception when there is no rows

Post by PascalD2 » Tue 11 Oct 2016 14:42

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

Shalex
Site Admin
Posts: 9103
Joined: Thu 14 Aug 2008 12:44

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

Post by Shalex » Fri 14 Oct 2016 15:11

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.

Post Reply