Firstly, I'm not sure why this is a problem... The pooling technique is
offered as a default so that the overhead is kept down when two connections
"appear" to be the same in the same process. This saves memory and resources
in general. If the connection times out because the "Connection Lifttime"
has expired, the the GC removes the pool from memory...
It's not a case of should, you "must" call Close()/Dispose()... Although
it's not as imperative as, calling "Open()" say, the fact is, failing to
call close leaves this connection wide open, and if you've numerous
different open connections, this in itself saps system resources.
Surely a simply find in the solution on "Open()" will give you an immediate
listing of all the instances where a connection is established?
Finally, you can turn pooling off by passing in "Pooling=false" in the
connection string. This would mean every new connection that is created
is
set up as a seperate connection, regardless if one (or hundred) just like it
have already been used.
http://msdn.microsoft.com/library/d...nectionpoolingforsqlservernetdataprovider.asp
If you employ proper connection maintenance from the start, it won't be a
problem...
Eric said:
Thank you for your reply.
SqlClient.SqlConnection should manually call Close() or Dispose() after
using. MSDN point out this. If we didn't call Close() or Dispose()
manually,
SqlConnecont won't be closed when the connection object is out of
range,
GC
would close the connection object in some magic time. That means, if we
don't call Close() or Dispose() as soon as possible, the
connection_pool
would be exhausted.
What's the worse, the connection_pool is organized by *process* and
*ConnectionString*. This means diffrent modules in one program, would
share
a same connection_pool. If one connection_pool was exhausted, we can
not
even find out which module cause this problem. In a huge project, this
will
be a very troublesome problem, I think.
"Dan =o)" <danielbass [at] postmaster [dot] co [dot] uk> дÈëÓʼþ
Eric,
The System.Data.SqlClient library is a pure .Net client interface to the
database. Therefore if the connection is not closed, there is the timeout
and garbage collector to sort it out if someone doesn't do the job of
closing it down manually.
What type of unmanaged resources are you refering too?
If the managed code is hooked into native code via the Interop's, then
the
garbage collector will again call the destructors on your unmanaged code
when it thinks you're finished with them during a clear up.
Therefore if the unmanaged code is not desroying its objects, the garbage
collector destroy these uncleared objects either as the onus lies with
the
unmanaged resource and not the .Net application.
for example: SqlConnection is used in my project, how can I know if all
connections were closed after open and execution. If some guys
forget
to
close connections after using, how can i check it out ?
best,
eric