Re: Question about IDispose

From: Alvin Bruney [MVP] (vapor)
Date: 02/25/04


Date: Wed, 25 Feb 2004 10:53:38 -0600


> For SqlConnection, IDisposable.Dispose() simply calls
> SqlConnection.Close() if the connection is not already closed. So it
> handles pooling just fine (at least as well as Close() does).

well that's really what i was looking for. if that's true, the problem is
resolved then. and i assume mysqlconnection would follow that same pattern.
i was thrown off by this response which seemed to indicate to me at least
that this wasn't happening

>Using should blindly call Dispose. It would be up to the object implementer
>to write a Dispose method that works properly with the pooling system

phew. ok all is well now. you guys can go back to work.

thanks

-- 
Regards,
Alvin Bruney [ASP.NET MVP]
Got tidbits? Get it here...
http://tinyurl.com/3he3b
"mikeb" <mailbox.google@mailnull.com> wrote in message
news:ugIYGz0%23DHA.2512@TK2MSFTNGP11.phx.gbl...
> Alvin Bruney [MVP] wrote:
>
> > Probably I was misunderstood. I'll restate for clarity.
> >
> >
> >
> > Implementing the using construct disposes of the object in question. The
> > connection pool is specifically setup to prevent object destruction
because
> > it is inherently expensive to create this object. It is much more
efficient
> > to reuse the object instead of destroying it.
> >
> > This behavior poses no problem in a windows environment because
connections
> > are cheap, however, the reverse is true in a web environment.
> >
> >
> >
> > Should the dispose pattern be smart enough to detect pooling? After
thinking
> > about it, Jon is right. Because of how the finalizer works, it is faulty
to
> > place dependency in the overridden dispose function. So it cannot check
for
> > a connection pool flag before destroying the object, at least based on
> > microsoft's best practices. So the *fix cannot come from the Dispose
layer.
> >
> >
> >
> > Should the fix be implemented at a higher level such as the connection
> > object layer? After thinking about it, I don't think so for the same
reason;
> > it forces the connection object into knowing more than it is supposed to
> > about the environment in which it is run. But this doesn't solve the
> > problem. The problem still remains that the benefits of the pool are
being
> > negated. Why is this important? Consider a high volume website fielding
> > 20000 hits per day. The benefits of pooling here make or break the
website.
> > Negating these benefits is simply not acceptable and must be avoided.
But
> > how can I avoid it if I don't know the negative effects?
> >
> >
> >
> > What I am suggesting is that Microsoft append a qualifying comment to
the
> > dispose pattern literature indicating that the using construct which
> > implements the IDispose pattern not be used in combination with object
> > pooling for web applications because the benefits of pooling may be
> > negatively affected. With that recommendation in the literature, I can
> > safely avoid the using construct at a high level and choose to manually
> > close my objects guaranteeing that the connection pool benefits remain
in
> > effect since calling close() only flags the object for reuse anyway.
> >
> >
> >
> >
> >>Are you *sure* that using the above pattern is actually ignoring
> >
> > connection pooling?
> >
> >
> >
> > No, I am not 100%sure. But based on the literature, I make an educated
guess
> > that it ignores pooling because the dispose implementation must make no
> > assumptions about the environment.
>
> The Dispose() implementation is provided by the class - so it knows the
> environment intimately.
>
> For SqlConnection, IDisposable.Dispose() simply calls
> SqlConnection.Close() if the connection is not already closed.  So it
> handles pooling just fine (at least as well as Close() does).
>
>
> -- 
> mikeb


Relevant Pages

  • Re: Question about IDispose
    ... > connection pool is specifically setup to prevent object destruction because ... > place dependency in the overridden dispose function. ... The benefits of pooling here make or break the website. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: ODBC/OLE DB Connection Pool
    ... > Connection Pool (I have already completed the TCP/IP tasks without ... turning off pooling is the errors you are seeing. ... problems are occurring with SQL Server; for example, ... ASP developers should open one connection per set of unique user ...
    (microsoft.public.data.ado)
  • Re: ODBC/OLE DB Connection Pool
    ... > Connection Pool (I have already completed the TCP/IP tasks without ... turning off pooling is the errors you are seeing. ... problems are occurring with SQL Server; for example, ... ASP developers should open one connection per set of unique user ...
    (microsoft.public.inetserver.asp.db)
  • Re: ODBC/OLE DB Connection Pool
    ... > Connection Pool (I have already completed the TCP/IP tasks without ... turning off pooling is the errors you are seeing. ... problems are occurring with SQL Server; for example, ... ASP developers should open one connection per set of unique user ...
    (microsoft.public.data.oledb)
  • Re: Question about IDispose
    ... connection pool is specifically setup to prevent object destruction because ... So the *fix cannot come from the Dispose layer. ... The benefits of pooling here make or break the website. ...
    (microsoft.public.dotnet.languages.csharp)