473,387 Members | 1,603 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dipose

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
Nov 21 '05 #1
3 1161
"Jason MacKenzie" <jm**********************@formet.com> 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/>

Nov 21 '05 #2

"Jason MacKenzie" <jm**********************@formet.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
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
Nov 21 '05 #3
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
Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Fredje | last post by:
Hello, I have the following problem: I'm making a application that add at runtime usercontrols. Each usercontrol have a function that converts a image. This conversion takes a while and at the...
4
by: Peter Oliphant | last post by:
I'd like to be able to destroy a Timer in it's own event handler. That is, within it's tick handler I'd like to delete the Timer itself (e.g., for one-shot timers). Is this possible? In general,...
6
by: Simon Harris | last post by:
Hi All, Do I need to use both Conn.Close() & Conn.Dispose() when I have finished with an SQL connection? -- I am using the free version of SPAMfighter for private users. It has removed...
4
by: Leandro Martins Berti | last post by:
Hi... I have a main MDI form where I load (in a menu click method) my MDI child forms, like in example below: private void tStpPrincipalUsers_Click(object sender, EventArgs e) { FormUsers...
1
by: Kevin Frey | last post by:
If you have a class that manages a resource (or something similar such as an unmanaged pointer), and you implement a Dispose( ) method, are you mandating to the users of your assembly that they...
1
by: Anonieko | last post by:
Understanding and Using Exceptions (this is a really long post...only read it if you (a) don't know what try/catch is OR (b) actually write catch(Exception ex) or catch{ }) The first thing I...
2
by: Scott McFadden | last post by:
I have a C++ CLI Managed DLL project which is consumed by C# clients. What is the recommended way for ensuring proper clean up of managed resources and native resources in a managed C++ class? ...
2
by: ziycon | last post by:
I get this error when trying to build with the below code!? protected override void Dispose(bool disposing) { if (disposing) { this.notifyIconMain.Dispose(); }
3
by: amitkgupta28 | last post by:
Hello All, I am working on .NET based project in Visual C++. I am using notifyIcon tool in my application. I am facing a weird problem. Even after closing the application, the notifyIcon still...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.