473,397 Members | 2,028 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,397 software developers and data experts.

When the connection to the database will be destroyed?

Hi,

I want to create a class (named "classA") in which a connection to a
database will be built. In another class (named "classB"), an object of the
"classA" is created and data are retrieved from the connection of the object
of the "classA". But in C#, we never need explicitly destroy an object, so
when will the connection to the database in the object be disconnected? I am
using C# to write the ASP.NET pages and I don't want to keep the database
connection after data have been retrieved. Do I need to destroy the object
explicitly? If yes, how?

Thanks

Q.
Nov 16 '05 #1
6 1599
You should close the connection as soon as you are done with it. You don't
need to destroy anything.

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

I want to create a class (named "classA") in which a connection to a
database will be built. In another class (named "classB"), an object of the "classA" is created and data are retrieved from the connection of the object of the "classA". But in C#, we never need explicitly destroy an object, so
when will the connection to the database in the object be disconnected? I am using C# to write the ASP.NET pages and I don't want to keep the database
connection after data have been retrieved. Do I need to destroy the object
explicitly? If yes, how?

Thanks

Q.

Nov 16 '05 #2
On the connection object, you need to call Close() or Dispose(). (Close is
prefered.) On Class A, you should implement IDisposable and call the
connection's Close method in the Dispose method of IDisposable. ClassB
should call classA.Dispose() when done using the classA object.

Search the help for Dispose to get more info.

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
Hi,

I want to create a class (named "classA") in which a connection to a
database will be built. In another class (named "classB"), an object of the "classA" is created and data are retrieved from the connection of the object of the "classA". But in C#, we never need explicitly destroy an object, so
when will the connection to the database in the object be disconnected? I am using C# to write the ASP.NET pages and I don't want to keep the database
connection after data have been retrieved. Do I need to destroy the object
explicitly? If yes, how?

Thanks

Q.

Nov 16 '05 #3
The Connection will be disconnected when you either Close or Dispose the
Connection object.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:#1**************@TK2MSFTNGP10.phx.gbl...
Hi,

I want to create a class (named "classA") in which a connection to a
database will be built. In another class (named "classB"), an object of the "classA" is created and data are retrieved from the connection of the object of the "classA". But in C#, we never need explicitly destroy an object, so
when will the connection to the database in the object be disconnected? I am using C# to write the ASP.NET pages and I don't want to keep the database
connection after data have been retrieved. Do I need to destroy the object
explicitly? If yes, how?

Thanks

Q.

Nov 16 '05 #4
"Kevin Spencer" <ke***@takempis.com> wrote in news:OGDJ1tNGEHA.3180
@TK2MSFTNGP12.phx.gbl:
The Connection will be disconnected when you either Close or Dispose the
Connection object.


Not true under default options. Calling Close() or Dispose() will release
the connection back into the pool, and it will be closed some time later if
it goes unused.

Mark
Nov 16 '05 #5
So, there is not any way to disconnect the connection at once after
retrieving the date? In another words, it is not neccessary to disconnect
the connection in ASP.NET?

Thanks

Q.

"Mark" <mark@--somewhere--.com> wrote in message
news:Xn******************************@207.46.248.1 6...
"Kevin Spencer" <ke***@takempis.com> wrote in news:OGDJ1tNGEHA.3180
@TK2MSFTNGP12.phx.gbl:
The Connection will be disconnected when you either Close or Dispose the
Connection object.

Not true under default options. Calling Close() or Dispose() will release
the connection back into the pool, and it will be closed some time later

if it goes unused.

Mark

Nov 16 '05 #6
If you do what I told you, everything will be fine. .Net manages the
Connection Pool.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Quentin Huo" <q.***@manyworlds.com> wrote in message
news:eD*************@TK2MSFTNGP11.phx.gbl...
So, there is not any way to disconnect the connection at once after
retrieving the date? In another words, it is not neccessary to disconnect
the connection in ASP.NET?

Thanks

Q.

"Mark" <mark@--somewhere--.com> wrote in message
news:Xn******************************@207.46.248.1 6...
"Kevin Spencer" <ke***@takempis.com> wrote in news:OGDJ1tNGEHA.3180
@TK2MSFTNGP12.phx.gbl:
The Connection will be disconnected when you either Close or Dispose the Connection object.


Not true under default options. Calling Close() or Dispose() will release the connection back into the pool, and it will be closed some time later

if
it goes unused.

Mark


Nov 16 '05 #7

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

Similar topics

6
by: Quentin Huo | last post by:
Hi, I want to create a class (named "classA") in which a connection to a database will be built. In another class (named "classB"), an object of the "classA" is created and data are retrieved...
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: 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
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
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.