Close the reader before closing the connection.

If you always close the DataReader before closing the connection, or is it ok to close the connection? Just closing the connection, does it effectively close the reader?

(This is for C # .net 3.5)

Thanks!

+4
source share
3 answers

In addition to clearly defining your intent, this can be found in the Microsoft documentation ( Extracting data using DataReader (ADO.NET) ):

You should always call the Close method when you are done using the DataReader object.

+5
source

Close also DataReader.

imo. if it implements IDisposable or has a .close () method or a similar construct mentioned in the documentation that you should call when you are done with this instance, do it. Do not rely on anything else to take care of it for you - unless the documentation clearly states that it is. For DataReader / DbConnection - the docs don't mention anything like that.

0
source

I prefer using C # with statment, which is called for dispose () for you. Here is a worthy explanation.

Using Status

0
source

Source: https://habr.com/ru/post/1305152/


All Articles