473,399 Members | 3,888 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,399 software developers and data experts.

Please explain the difference between close, dispose, = nothing on sqlClient.

Does anyone can explain the details between
Connection.close
Connection.dispose
Connection = nothing

If I just need to close the connection and release the memory,
do I need to write all three statement?
Thank you.

Aug 29 '06 #1
3 4599
Close - closes the Connex and makes it available for connex pooling
Displose - closes the Connex and makes it available for connex pooling and
clears stateful information
Connection = nothing will leave the connex for garbage collection. If an
open connex was set to nothing, then you are at the mercy of GC to come call
the finalizer i.e. your connex is going to be unpooled for a fairly long
time.

In short.

#1 - Dispose is the best
#2 - Close is almost as good
#3 - Connection = nothing is horrible.

Did that help ya? :)

- Sahil Malik
http://www.winsmarts.com
http://blah.winsmarts.com

"Cylix" <cy*******@gmail.comwrote in message
news:11*********************@m79g2000cwm.googlegro ups.com...
Does anyone can explain the details between
Connection.close
Connection.dispose
Connection = nothing

If I just need to close the connection and release the memory,
do I need to write all three statement?
Thank you.

Aug 29 '06 #2
Cylix,

Close makes it possible for the SQLServer to remove the connection from the
connection pooling.

Dispose is removing as extra the reference to the connectionstring in the
connection object. The same as
setting before the close the XXXconnection.connectionstring to nothing.
Dispose is calling Close before that and therefore has for the
connectionpooling the same effect. AFAIK is that connectionstring the only
reference that can prevent it from being garbaged and therefore this will be
done.

Setting it to nothing has sense if you have set your connection globally
because than the reference to that will be cleaned and the last one can be
garbaged, in other cases it is without sense. Declaring it globaly is by
instance the way as versions 2002/2003 do it using the wizards. I would try
to prevent that.

I hope this gives an idea,

Cor

"Cylix" <cy*******@gmail.comschreef in bericht
news:11*********************@m79g2000cwm.googlegro ups.com...
Does anyone can explain the details between
Connection.close
Connection.dispose
Connection = nothing

If I just need to close the connection and release the memory,
do I need to write all three statement?
Thank you.

Aug 29 '06 #3
Oh, Thanks Sahil and Cor.
You do really helpful.

Aug 29 '06 #4

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

Similar topics

5
by: Martin | last post by:
Dear Group Sorry for posting this here. I'm desperate for a solution to this problem and thought some of you might have come across it with .NET and SQL Server. Let's assume I've the following...
5
by: Franco, Gustavo | last post by:
Hi, I have a question, and please I need a answer. How can I finalize a thread running with Application.Run (I need the message loop!!!) without call Thread.Abort?. I want to call...
7
by: Willem van Rumpt | last post by:
Hi all, coming from an unmanaged programming background, I took my time to sort out the IDisposable and finalizer patterns. Just when I thought I had it all conceptually neatly arranged, the...
1
by: Bob | last post by:
Is this a good way to close DB Connection in ASP.NET? I've been trying to come up a way to close DB connection automatically (or sort of) in my ASP.NET application without having to write the...
8
by: Paul W | last post by:
Hi - in an asp.net application, how should I close out a sqlclient.connection? What combination and order of Conn.close conn.dispose conn=nothing Should I use? Specifically, is the...
2
by: Bert Szoghy | last post by:
Hello, I am missing something about Visual Basic .NET module variables and window close events. In the following code, after opening Form2 by clicking a button on Form1 and then closing...
1
by: David Van D | last post by:
Hi there, A few weeks until I begin my journey towards a degree in Computer Science at Canterbury University in New Zealand, Anyway the course tutors are going to be teaching us JAVA wth bluej...
0
by: almurph | last post by:
Hi everyone, Hope that you can help me please. I am parsing approx 1.34M record in a database. I read a line, parse it and then write out this new line to a new column. However I have notice...
3
by: Joris De Groote | last post by:
Hi, I use Adobe Acrobat to read tekst from PDF files. After that the file has been read, I move the file in a folder (using the date I got from the text I got from Acrobat). Now here is my...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.