Adrift in .Net
If you need to stop a datareader in the middle, instead of at the end, you have to call cancel on the command object. Calling the Close() method will result in a timeout exception.
using (SqlCommand cmd = new SqlCommand(sql, conn)){ XmlReader reader = cmd.ExecuteXmlReader(); reader.Read(); while (!reader.EOF) { if (this.Cancel) { cmd.Cancel(); reader.Close(): break; } holder = reader.ReadOuterXml(); }}
using (SqlCommand cmd = new SqlCommand(sql, conn)){ XmlReader reader = cmd.ExecuteXmlReader(); reader.Read();
while (!reader.EOF) { if (this.Cancel) { cmd.Cancel(); reader.Close(): break; } holder = reader.ReadOuterXml(); }
Disclaimer The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.