i want simple exlaination from you guyz that why we close the datareader object
like
datareader dr = new datareader;
//assume that some code is here.
dr.close();
and when we close datareader object...
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Karthikeyan KRank #554 · 4.4K reputationPosted Sep 8, 2015, 7:28 PM EDT
Remarks
You must explicitly call the Close method when you are through using the SqlDataReader to use the associated SqlConnection for any other purpose.
The Close method fills in the values for output parameters, return values and RecordsAffected, increasing the time that it takes to close a SqlDataReader that was used to process a large or complex query. When the return values and the number of records affected by a query are not significant, the time that it takes to close the SqlDataReader can be reduced by calling the Cancel method of the associated SqlCommand object before calling the Close method.
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, you should 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 Garbage Collection.
Karthikeyan KRank #554 · 4.4K reputationPosted Sep 8, 2015, 7:31 PM EDT
Rojalin SahooRank #2,919 · 493 reputationPosted Sep 8, 2015, 8:56 PM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted Sep 8, 2015, 9:11 PM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Sep 8, 2015, 9:37 PM EDT