PC Review


Reply
 
 
Jason MacKenzie
Guest
Posts: n/a
 
      22nd Nov 2004
I have a class that does some database acess. I'm pretty meticulous in
closing all connections when done with them and disposing of all objects
that have a dispose method .

Does this class need to have a dispose method of its own? I'm a little
unclear on this?

Thanks,

Jason MacKenzie


 
Reply With Quote
 
 
 
 
Herfried K. Wagner [MVP]
Guest
Posts: n/a
 
      22nd Nov 2004
"Jason MacKenzie" <(E-Mail Removed)> schrieb:
>I have a class that does some database acess. I'm pretty meticulous in
>closing all connections when done with them and disposing of all objects
>that have a dispose method .
>
> Does this class need to have a dispose method of its own? I'm a little
> unclear on this?


You can implement the 'IDisposable' interface and close the connections in
the class' 'Dispose' method. This would make sense.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

 
Reply With Quote
 
David Browne
Guest
Posts: n/a
 
      22nd Nov 2004

"Jason MacKenzie" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
>I have a class that does some database acess. I'm pretty meticulous in
>closing all connections when done with them and disposing of all objects
>that have a dispose method .
>
> Does this class need to have a dispose method of its own? I'm a little
> unclear on this?



The class must implement IDisposable just in case it aggregates a disposable
object.

If your class has a member variable of type IDbConnection, then yes, it
should implement IDisposable and IDisposable.Dispose should invoke
IDbConnection.Dispose.

If, on the other hand, your class uses IDbConnections objects only as local
variables inside its methods, then no, you don't need to implement
IDisposable.


David


 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      22nd Nov 2004
Jason,

>I have a class that does some database acess. I'm pretty meticulous in
>closing all connections when done with them and disposing of all objects
>that have a dispose method .


Because that it is the connection which does as well the connectionpooling
it is advised to close as often as possible your connections. However as one
of the exceptions in this case with myconnection.dispose. When you need them
again you create them new every time.

(This is an advice in situations with more than 100 open connections)

I see no reason why you would dispose all the other objects by the way.

Just my thought,

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dipose vs Destructor Scott McFadden Microsoft VC .NET 2 19th May 2007 02:55 AM
Is Dipose( ) a contractual obligation, if you provide one? Kevin Frey Microsoft VC .NET 1 10th May 2006 06:16 AM
Dipose() Doubts Leandro Martins Berti Microsoft C# .NET 4 3rd Apr 2006 08:58 PM
Dipose() problem Lloyd Dupont Microsoft Dot NET Compact Framework 0 19th May 2004 03:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:13 PM.