Search code examples
c#.netdatareader

Close reader before closing connection


Should you always close a DataReader before closing the connection, or is it okay to just close the connection? By just closing the connection does that effectively close the reader?

(This is for c#.net 3.5)

Thanks!


Solution

  • Aside from making your intent clear, there is this from the Microsoft documentation (Retrieving Data Using a DataReader (ADO.NET)):

    You should always call the Close method when you have finished using the DataReader object.