alainc

alainc

  • NA
  • 23
  • 0

Close connection in finalizer

Feb 24 2005 7:10 AM
In a class of my asp.net application, I open connection in constructor and I want close connection in finalizer method but .close fails. I have read this http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlconnectionclassclosetopic.asp CAUTION 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 Programming for Garbage Collection. How can I close this connection? Thankssss

Answers (2)