Question about Dispose

A

Angel Saenz-Badillos[MS]

The following information is not true for SqlClient:

"The Dispose() method releases all resources associated to the connection
object (including removing it from the connection pool). Not a good practice
to call Dispose() unless you want connection to be removed from the
connection pool."
</Warning>

It is very simple to write an application that disproves this so if you have
any questions you should try it yourself. Dispose only does two things,
first it deletes the connection string and then it calls Close. There is no
functional difference between Close and Dispose and you can call either or
both without a problem.

It is highly recommended that you call Close inside of a Finally block or
that you use the "using" construct when using SqlConnections to make sure
that the connections are properly closed and that you don't leak connections
in cases where execute throws an exception.
Hope this helps
 
A

Angel Saenz-Badillos[MS]

Kudos on trying it for yourself! Yes you are completely correct, Close and
Dispose are functionally exchangeable and when using Pooling Dispose will
certainly not remove the connection from the pool.

--
Angel Saenz-Badillos [MS] Managed Providers
This posting is provided "AS IS", with no warranties, and confers no
rights.Please do not send email directly to this alias.
This alias is for newsgroup purposes only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top