Marcel,
It is not a destructor. It is a finalizer, which means that the object
does not get cleaned up when it goes out of scope. In this case, you need
to implement the IDisposable interface and expose an implementation of
Dispose which will close the handle when you are done with it.
Additionally, as a general rule, I wouldn't keep database references as
fields in classes anyways. I would create my connection in my method as
needed, and then close the connection when I am done with it (in the
method). If I do store it on the class level, then that says to me that the
class is a utility class which ultimately has a short life as well.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
-
mv*@spam.guard.caspershouse.com
"Marcel Hug" <ma**********@ch.abb.com> wrote in message
news:u6**************@TK2MSFTNGP14.phx.gbl...
Hi NG !
I would like to close my OleDBConnection in the destructor of the class,
but i get a failure, that the handle is not initialized. I read in the
msdn, that it is not good the close the oledbconnection in the finalize.
So it's the same with the destructor ?
Thanks ?
Regards