By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,847 Members | 2,402 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,847 IT Pros & Developers. It's quick & easy.

iDisposable and database connection to SQL

P: n/a
I have created a class that connects to a SQL database when it is
created. This is a maintenance application that re-creates this class
at regular intervals. I am worried that I will be creating a lot of
connections to the database and leaving them open until the GC decides
to clean them. When the variable for the class goes out of scope is the
database connection closed or will it remain ipen until the GC fires?
This object may get created every 10 minutes.

Should I implement iDisposable and use the 'Using' block when I create
this object?
Thank you!
Karl

May 17 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Karl,

Why isn't your app explicitly closing its connection to the database?

Kerry Moorman
"karl" wrote:
I have created a class that connects to a SQL database when it is
created. This is a maintenance application that re-creates this class
at regular intervals. I am worried that I will be creating a lot of
connections to the database and leaving them open until the GC decides
to clean them. When the variable for the class goes out of scope is the
database connection closed or will it remain ipen until the GC fires?
This object may get created every 10 minutes.

Should I implement iDisposable and use the 'Using' block when I create
this object?
Thank you!
Karl

May 17 '06 #2

P: n/a
Everything is handled by the class so it should be able to close the
connection when it is disposed of. I didn't really want the application
to have to tell it that is was done with it. That is why I was thinking
about using the Dispose sub...

Thanks
Karl

May 17 '06 #3

P: n/a
Karl,

If you dispose or close it is in this class not so important, the dispose
calls the close.

However the GC is never disposing so will not close as well.

Cor

"karl" <ka*****@pacbell.net> schreef in bericht
news:11**********************@i39g2000cwa.googlegr oups.com...
Everything is handled by the class so it should be able to close the
connection when it is disposed of. I didn't really want the application
to have to tell it that is was done with it. That is why I was thinking
about using the Dispose sub...

Thanks
Karl

May 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.