InvalidOperationException: Timeout - recursive DB access

utteludge

New Member
currently I have a serious problem with one of my web applications which runs into a Timeout Exception around half a dozen times a day. Error: "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".After a lot of googling I found out that the problem has something to do with unclosed connections. So I checked all functions that access the database in any way until I stumbled upon this one:\[code\] Private Sub getOrgas(ByVal orgID As String) Dim Id = orgID orgColl.Add(Id) While (Not IsNothing(Id)) Dim conn = Database.DbWrapper.GetConnection(1, Integration.Mandanten.DatabaseType.AddonSQL) Dim paras As New HashSet(Of System.Data.Common.DbParameter) Dim orgatmp As String paras.Add(New SqlClient.SqlParameter("@Id", orgID)) Dim dr = Database.DbWrapper.GetDataReaderFromStoredProcedure("stp_Orgas_Get", paras, conn) While dr.Read If Not valueInColl(CStr(dr(0))) Then orgatmp = dr(0).ToString orgColl.Add(orgatmp) getOrgas(orgatmp) End If End While dr.Close() conn.Close() Id = Nothing End While End Sub\[/code\]As you can see this function executes a stored procedure and runs the results through a while loop where it calls the function again if a specific condition -valueInColl-. Now in that way it is possible that there are 20 or more open connections. It has nothing to do with the timeout-value which is set via the GetDataReaderFromStoredProcedure to 600 which actually should be enough. To be sure I doubled the value and will roll it out this evening. I'll see whether that helped within the next day then.I believe the problem is that there are too many open connections at the same time, because of the recursive function, but I have no clue how to solve this.I couldn't find anything as to how to edit the max connections. I'm not even entirely sure where have to set it. Is it the IIS, the DB itself or is it a programming-parameter (VB.net/ASP.NET).Would be nice if you guys could help me out here.
 
Top