[dba-VB] C# - what does this mean

jwcolby jwcolby at colbyconsulting.com
Sun Jul 25 14:30:11 CDT 2010


From:

http://msdn.microsoft.com/en-us/library/haa3afyz%28VS.71%29.aspx

Closing the DataReader

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

If your Command contains output parameters or return values, they will not be available until the 
DataReader is closed.

Note that while a DataReader is open, the Connection is in use exclusively by that DataReader. You 
will not be able to execute any commands for the Connection, including creating another DataReader, 
until the original DataReader is closed.

     Note   Do not call Close or Dispose on a Connection, a DataReader, or any other managed object 
in the Finalize method of your class. In a finalizer, only release unmanaged resources that your 
class owns directly. If your class does not own any unmanaged resources, do not include a Finalize 
method in your class definition. For more information, see Programming for Garbage Collection.


NOTICE the Note above.  Why would you NOT call close at the very least.  I understand Dispose - that 
is the garbage collector's job to do that when it decides it needs to but close?

-- 
John W. Colby
www.ColbyConsulting.com



More information about the dba-VB mailing list