CKKwan said:
Connection.Open();
The execute and command and read something.
Before reading is complete, I decided to call:
Connection.Close();
Question:
Must I call DataReader.Close() before closing the connection?
First call Close on the reader, then Dispose.
There's a tiny problem with SqlDataReader btw. If your data reader
points to a large resultset from a complex query, and you fetch say 100
rows and then call Close() on it, the SqlDataReader will consume the
rest of the rows and then close the datareader. This can take a long
time. In these cases, try calling Cancel() first, as stated in the MSDN
documentation for SqlDataReader. One caveat: if the command is in a
transaction, it's better not to cancel.
FB
--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website:
http://www.llblgen.com
My .NET blog:
http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------