My method which calls SQL Server returns a DataReader
but because of what I need to do - which is return the DataReader
to the calling method which resides in a page code-behind - I can't close the connection in the class of the method which calls SQL server. Due to this, I have no finally or using blocks.
Is the correct way of disposing resources to make the class implement IDisposable
? Alternatively should I explicitly dispose the unmanaged resource (class-level fields) from the caller?
EDIT: I send the datareader back because I need to bind specific data from the datareader to a listitem control, so in the calling class (Codebehind page), I do:
new ListItem(datareader["dc"]); (along those lines).