Re: What is the difference between Dispose and Close



Sourcery? Dispose and Close both return the connection to the pool. If they
were calling neither or the logic let the PSP sneak away without calling one
or the other, adding Dispose would do the trick--assuming it's actually
called. I've seen lots of cases where developers pass a DataReader to
another routine that fails to close the DataReader (assuming they remembered
to use the correct CommandBehavior). I've seen situations where the Close
(or Dispose) is there, but the logic bypasses it if there is an exception
(the Close is not in the Finally).

Unless it's a bug (which I doubt), I don't expect that Dispose will cure any
more connection pool issues than Close. Is there a code example somewhere
that shows that Dispose works where Close does not? If so, I know a number
of folks on campus that would love to see it.



--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________


"Cor Ligthert" <notmyfirstname@xxxxxxxxx> wrote in message
news:uH3U2KFbFHA.3132@xxxxxxxxxxxxxxxxxxxxxxx
> Bill,
>
>> As far as pooling behavior, Dispose and Close both return the Connection
>> to the pool for reuse. Each of the .NET providers implements a Connection
>> pool--it's part of the core functionality.
>>
> Why were there than so many people in these newsgroup, who had problems
> with the Connection Pool, for whom, after that I advised to change the
> close for dispose (according to the messages from Angel), the Connection
> pool problems were gone?
>
> Cor
>


.



Relevant Pages

  • Close and Dispose argument
    ... here is an email conversation between me and Microsoft ... connections from the pool is still a debate. ... Programming with Microsoft ADO.NET" module 2, p 18: "Calling the Dispose ... method removes the conneciton from the connection pool". ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: .NET connection pool problems
    ... both Dispose and Close are acceptably best practices for ... closing a connection and returning it to the pool. ... Here is a snippet from the Data Access Architecture best practices article ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Max pool size reached exception when trying to open a new connection
    ... Hi i am wrapping the sqlconnection in using statement.so there is no ... doubt that dispose is not getting called on sqlconnection. ... prior to obtaining a connection from the pool. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: VS2005 and SQL Express: Internal .Net Framework Data Provider
    ... connection object you use. ... public void CreateConnection{ ... // Close first and dispose the existing data reader is there ... release resources used by the object ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Ideal way to retrive dataset.
    ... In general it is a good idea to call dispose on any method that implements ... The best way to use the SqlConnection object in c# is ... closeand disposeconnection, and dispose SqlDataAdapter also. ... the connection will go back to the pool in this case. ...
    (microsoft.public.dotnet.framework.adonet)