Connection Pooling in SQL Server

E

Eladio Rincón

Hi,

I know that this bug exists, but it is different behavior ...
BUG: Performance Counters for SQL Server .NET Data Provider Are Not Reset
http://support.microsoft.com/default.aspx?scid=kb;en-us;314429

I use this method to get the counterValue:

Private Function GetCounterValue(ByVal objectName As String, ByVal
counterName As String, ByVal instanceName As String, ByVal machineName As
String) As Single
Try
Dim counter As New Diagnostics.PerformanceCounter
With counter
..CategoryName = objectName
..CounterName = counterName
..InstanceName = instanceName
..MachineName = machineName
End With
Return counter.NextValue()
Catch ex As Exception
Return 0
End Try
End Function


and those are the calls I do:

Dim server As String = "tcp:ELADIO"
Dim conn As New SqlConnection("server=" + server +
";Database=northwind;Integrated Security=SSPI;")
Console.WriteLine("#pooled connections: " + GetCounterValue(".NET CLR Data",
"SqlClient: Current # pooled connections", "pooling", "ELADIO").ToString)
conn.Open()
Console.WriteLine("Conected...")
Console.WriteLine("#pooled connections: " + GetCounterValue(".NET CLR Data",
"SqlClient: Current # pooled connections", "pooling", "ELADIO").ToString)
conn.Close()
Console.WriteLine("Closed...")
Console.WriteLine("#pooled connections: " + GetCounterValue(".NET CLR Data",
"SqlClient: Current # pooled connections", "pooling", "ELADIO").ToString)

the results I get are the following:
#pooled connections: 0
Conected...
#pooled connections: 2
Closed...
#pooled connections: 2

from those results I see two points:
-AFAIK, while the connection is in use, it can not be pooled; I think that
the counter notifies that the connection is in the pool but it's not in
really
-I get the results multiplied by 2; I only open one connection and the
result is 2; I'm sure I only open one instance of the connection and I'm
sure aswell that I have only one instance of the application (named
"pooling").

Can you help me to clarify any of those points?
Thank you,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top