Connection Pooling - Bug in .NET ?
-
I have run a few tests and am now convinced that there must be a problem with connection pooling, or connections not being freed up correctly by .NET My test is as follows. I have an XML Web Service running on an IIS site running on .NET 1.0 with all service packs applied with the following site configuration: Anonymous Access: Yes User name: domain\xxxxx <-- this username has access to the SQL Server Allow IIS to control password: Yes Basic Authentication: No Integrated Windows authentication: Yes The test method I am calling is written in VB.NET (code follows), when I pass in '50', the method creates 50 connections, pauses for 20 seconds to hold them open, and then they are closed and disposed - this works fine. The problem happens when I pass in '150'. The following exception is thrown;
System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.InvalidOperationException: Timeout expired. The timeout period elapsed prior to obtaining a connection from the pool. This may have occurred because all pooled connections were in use and max pool size was reached. at System.Data.SqlClient.SqlConnection.Open() at MyService.DataService.AuthenticateUser(String DomainUsername) in \\servername\CREQSERVICE\DataService.asmx.vb:line 172 --- End of inner exception stack trace ---
But even worse, the connections never seem to be released and the server becomes unstable; further connections to IIS time out. If I stop/start the web service it doesn't clear the connection pool. I have tested this on three different test servers, and get the same problem. Any help with this would be appreciated, I'm trying to get some code into production, and this problem has delayed me for a week already. Does anyone know if there is a known bug with connection pools? Code used for testing:<WebMethod()> Public Function CreateTestConnections(ByVal NumberOfConnections As Integer) As String 'This is for testing only!, remove from production code Dim conSQL As Array = Array.CreateInstance(GetType(SqlConnection), NumberOfConnections) Dim t As Long For t = 0 To NumberOfConnections - 1 Try conSQL(t) = New SqlConnection(ConfigurationSettings.AppSettings("connectionstring")) conSQL(t).Open() Catch e As Exception End Try Next t 'pause for 20 seconds Dim Start, Finish, TotalTime As Double