2
Answers

Close connection in finalizer

Ask a question
alainc

alainc

19y
3.4k
1
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)
Next Recommended Forum