473,396 Members | 1,895 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,396 software developers and data experts.

iDisposable and database connection to SQL

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
3 1728
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: codymanix | last post by:
Last night I had several thought about RAII and want to discuss a bit. Why doesn't CSharp support destructors in structs? Wouldn't that make RAII possible like in C++? When the struct goes out of...
6
by: newbie | last post by:
I have Class A that implements IDisposable, within this class i have method A that creates a new Sqlconnection object and execute some stored proc, in Class B, I create an instance of Class A object...
4
by: Arjen | last post by:
Hi, Here I have made some sample code. I want to know if I'm using IDisposable on the right way. public class Person { public string name; public string address; }
1
by: jinfeng_Wang | last post by:
hi, I have a question about the difference between SqlConnection.IDisposable.Dispose() and SqlConnection.Dispose(). Both of them realize the function of releasing the connection to the...
3
by: Dave | last post by:
I trying to determine the best pattern for designing my business and data layers... Can the instance of the business object eventually cause memory leaks in Example 1? If your business class...
3
by: kalamantina | last post by:
How to rewrite this snippet if you must implement IDisposable private static void OpenConnection() { string connectionString = GetConnectionString(); StringBuilder errorMessages = new...
12
by: Cordell Lawrence \(News Group\) | last post by:
There an ongoing discussion between a colleague and myself about the usefulness of the IDisposable pattern beyond the reclamation of unmanaged resources. The discussion is somewhat lengthy so I...
11
by: Mark Rae | last post by:
Hi, Following on from the recent thread about why HttpWebRequest doesn't implement the IDisposable interface, I got to wondering whether people make their custom classes inherit IDisposable or...
1
by: tascien | last post by:
I am getting confused about the role of any of the above methods and interfaced. But what I want to do is simple... the Destructor such as the one in C#. Basically, my only issue, is to make...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.