Last post Aug 26, 2011 10:20 AM by azarc3
Apr 20, 2006 03:19 PM|Ivoryzion|LINK
Apr 25, 2006 11:20 PM|Iori_Jay|LINK
Hi, to understand Dispose method for a SQLConnection, you can take a look at this post:
Aug 26, 2011 10:20 AM|azarc3|LINK
Answers to your questions (as best as I can provide, even though I'm 5 years late... but someone else may benefit.):
1) Is this design good/bad?
As stated this is bad design. See the answer to #3 for they "why".
1) Is this a bug?
2) Do I need a try/catch in a destructor? Is it good programming practice?
No, and no... not as pertains to this situation. See the answer to #3 for the "why".
3) Why is this happening?
The problem is that you're trying to close a managed object in the class destructor. You can get the actual details here:
Long story short, you should only mantain open connections for as long as you need them, and then only for a reasonable unit of work. Typically this doesn't not span the entire page lifecycle. A better practice would be to use a property on the page that
checks to see if a backing field has an already open connection; if not, then create and open one for use; if so, pass the one that already exists.
4) What is the meaning of life?
I'm still searching for that one chief. =/