473,321 Members | 1,669 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,321 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 18 '05 #1
6 1121
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 18 '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 18 '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 18 '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 18 '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 18 '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 18 '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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.