connection from asp.net to sqlserver2000 remains open and blocks other connections.

  • Thread starter Thread starter avnrao
  • Start date Start date
A

avnrao

best way is to override dispose on that general class.. and you can call it
explicitly or use using() block.
deconstructor gets called when object is removed (i guess when GC is
collecting the object)..

destructors also be called when program exists. is your program existing
here?
Av.
 
Do you have a message saying the connection pool is full ?

Remember that finalization in .NET is not deterministic and here I suspect
you still have a reference.

I would close explicitely the DB connection as soon as I'm done with it.

Patrice
 
Hi,

i use asp.net and i have a general class that manages database access using
ado.net and sqlclient provider.
this class upon deconstructor closes connection to DB.

it appears on sql 2000 manager when i look in management/current
activity/Process Info that my connections stays open and the number of
connections open is increasing each request.

what am i missing / doing wrong here.
thanks for any input from your experience.

z.
 
well, since it's an aspx page, the program is aspnet.exe on win2k or
w3wp.exe on win2003 and this process should stay in memory for long time.
so i need to take care of my objects my self.
thanx.
 
ADO.NET manages connection pooling itself, If you do a close or dispose
it does'nt really mean that connection to db server is closed. When you call
connection.close or adapter.close, it actually closes connection to your
applications
object with ado.net, on the other hand ADO.NET is itself maintaining
connections
with database.
Its very important to close both data reader and connection as soon as they
are no longer needed. if you do not do this, they will go out of scope and
the
application will leak a connection and u'll see one more connection.

check this msdn documentation for reference:
http://msdn.microsoft.com/library/en-us/vbcon/html/vburfintroductiontoadoconnectiondesigntools.asp
 
As someone else has stated, you should always close data readers and db connections right after you are finished using them.

Also, you may never call other managed objects in Finalizers, because you do not know if the other objects have already been finalized by the GC. The order in which objects are finalized is not known. So calling Close on an SqlConnection object in the finalizer of your object is a very bad idea.
 
It is not a good idea to let the finalizer (or deconstructor) close
connections--it simply won't work. As others have said, close the
connections explicitly.

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