Connection pool in .net

Imports System.Data.SqlClient

Module Module1

    Sub Main()
        Dim iCount As Integer = 1
        Try
            Do
                Dim sqlConn As New  _
                SqlConnection("Data Source=localhost;trusted_Connection=yes;initial catalog = MyDatabase;max pool size =100;")
                sqlConn.Open()
                Trace.WriteLine("opening connection " & CStr(iCount))
                'sqlConn.Close()
                'Trace.WriteLine("closing connection " & CStr(iCount))
                'sqlConn.Dispose()
                'Trace.WriteLine("disposing connection " & CStr(iCount))
                iCount = iCount + 1
            Loop Until iCount > 20000
        Catch ex As Exception
            Trace.WriteLine(ex.ToString)
        End Try
    End Sub

End Module

If I run this code, this test application will open 115 database connections before it throws an exception The timeout period elapsed prior to obtaining a connection from the pool. But there are only 100 connections in the application pool. How is this possible?

+3
source share
1 answer

Guess since you do not keep references to objects of open connection, perhaps the first 15 become accessible and reused? Do you still get 115 if you click the connections on List<>?

+3
source

All Articles