Connection Pooling

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have an application, which opens many connection and after completing work
never closes connection. This is becoming a problem on sql server side.

I am thinking to write a tool which will close all the sleeping connection
at one run.

Is this possible ?. how will I get a info about connection from sql server?


Kishor
 
Hello kishor,

The real trick is to get rid of th code that never closes the connection.
I know you're hoping to fix it with something less than that, but I doubt
your problems will disappear unless you fix it right.


Thanks,
Shawn Wildermuth
Speaker, Author and C# MVP
http://adoguy.com
 
To add to what Shawn said, you can more easily clean up connections by
wrapping them in using blocks. These are supported for both C# and VB
in 2.0. At the end of the using block, the connection is automatically
closed/disposed and returned to the pool so that it can be reused.

Using connection As New SqlConnection(connectionString)
connection.Open()
' Do work here.
End Using

using (SqlConnection connection = new SqlConnection(connectionString))
{
connection.Open();
// Do work here.
}

--Mary
 
Back
Top