Do I need to dispose a sqldatareader after it is created?
SqlDataReader reader;
---
---
---
reader.Close();
reader.Dispose();
See Question&Answers more detail:osDo I need to dispose a sqldatareader after it is created?
SqlDataReader reader;
---
---
---
reader.Close();
reader.Dispose();
See Question&Answers more detail:osRule of thumb: if a class implements IDisposable you should always call the Dispose method as soon as you have finished using this resource. Even better wrap it in a using statement to ensure that the Dispose method will be called even if an exception is thrown:
using (var reader = conn.ExecuteReader())
{
...
}