Question on SqlDataReader.Close

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi all,

According the MSDN documentation on the SqlDataReader.Close method, it says
that:

The Close method fills in the values for output parameters, return values
and RecordsAffected, increasing the amount of time it takes to close a
SqlDataReader....

Is that mean before I can retrieve the value of stored procedure output
parameters, I should call the SqlDataReader.Close method? But in some sample
code I found on the web, it reads the output parameters before calling the
Close method?

Which is more appropriate?

Thanks for help!


Best Regards,
Tony
 
Hi all,

According the MSDN documentation on the SqlDataReader.Close method, it says
that:

The Close method fills in the values for output parameters, return values
and RecordsAffected, increasing the amount of time it takes to close a
SqlDataReader....

Is that mean before I can retrieve the value of stored procedure output
parameters, I should call the SqlDataReader.Close method? But in some sample
code I found on the web, it reads the output parameters before calling the
Close method?

Which is more appropriate?

Thanks for help!


Best Regards,
Tony

I was under the impression that this behavior regarding returns from command
executions was for the ExcecuteNonQuery method. Maybe I'm wrong, The only time
I deal with returns from queries (except for returned rows) is when doing an
insert when I want to get the scope_identity() returned.

I probably don't understand what you are asking. Can you give an example of the
code?

Otis Mukinfus
http://www.otismukinfus.com
 
Hi,

AFAIK when you are returning records from stored procedure all records have
to be returned to get the output parameters values.
So, yes, Close will fetch all the remaining records and set parameter
values.
It doesn't make much difference since you will have to call Close anyway -
regardless if you want to read or not all records.
 
Thanks for Miha's quick response.

Hi Tony,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you need to know if we can get the
output parameters before calling SqlDataReader.Close method. If there is
any misunderstanding, please feel free to let me know.

As far as I know, we cannot do this. Because, before Close method is
called, the output parameter values are not get. So if you're trying to
retrieve the values, you will get a null reference.

HTH.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
You're welcome, Tony.

Thanks for sharing your experience with all the people here. If you have
any questions, please feel free to post them in the community.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."
 
Back
Top