Possible SQL Server connection leak in BLToolkit

648 views
Skip to first unread message

Bryan Ellis

unread,
Aug 2, 2012, 12:44:59 PM8/2/12
to blto...@googlegroups.com
HELP! I have a windows service that every 3 seconds checks for items to process and processes them if found. The issue is that I am getting the following dreaded exception:
BLToolkit.Data.DataException: 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. ---> 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.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.SqlClient.SqlConnection.Open()
at BLToolkit.Data.DbManager.ExecuteOperation(OperationType operationType, Action operation) in c:\builds\2\AQ2.Core\AQ2.Core Main Build\Sources\AQ2.Core\AQ2.Core\IncludedCode\BLToolkit\Data\DbManager.cs:line 4392
I just updated my source to match the latest as of yesterday (4.1.10-9-ge72c6a4). I was seeing the error previously when my code was at version 4.1.8.3-21-g7ed6c0c.
When searching for help on this error I was lead to the Performance Counter ".NET Data Provider for SqlServer", "NumberOfReclaimedConnections"for a specific instance (my service process). The information mentioned that any increase in this number is due to connections that are closed by the GC rather than explicitly. This would then cause all connections in the pool to become used and the timeout error to occur if the requested connections are faster than the GC collection.
Has anyone else seen this issue? I am using BLToolkit for all of my connections and I am placing all DBManager objects in using constructs to make sure they are disposed.
Thanks,
Bryan

Igor Tkachev

unread,
Aug 2, 2012, 1:03:10 PM8/2/12
to Bryan Ellis, blto...@googlegroups.com
Hello, Bryan.

How do you open your connection?
-- 
Regards,
Igor

Bryan Ellis

unread,
Aug 2, 2012, 1:17:10 PM8/2/12
to Igor Tkachev

Hi Igor,

 

Thanks for the fast response.  I call my GetDbManager routine which looks like this:

 

public DbManager GetDbManager()

{

    var db = new DbManager(_dataProvider, ConnectionString);

    db.MappingSchema = new aq2DefaultMappingSchema();

    return db;

}

 

I do this in a using:

 

using (DbManager db = GetDbManager())
{
}

 

Normally I am simply passing the db variable to my GetAccessor<> method calls to reuse the same DbManager.  I seldom make any direct calls to the DbManager.

 

Did I miss something important?

 

Thanks again,

 

Bryan

Bryan Ellis

unread,
Aug 6, 2012, 8:44:45 AM8/6/12
to Igor Tkachev

Igor,

 

I used the RedGate Memory Profiler and found that one of my objects had an event reference to an object referencing the DbManager.  After adding IDIsposable to the object and “using” constructs my problem no longer exists.

 

I apologize for even questioning the Toolkit.

 

Thanks again,

 

Bryan

 

From: Bryan Ellis
Sent: Thursday, August 02, 2012 12:17
To: blto...@googlegroups.com
Subject: RE: [bltoolkit] Possible SQL Server connection leak in BLToolkit

 

Hi Igor,

 

Thanks for the fast response.  I call my GetDbManager routine which looks like this:

 

public DbManager GetDbManager()

{

    var db = new DbManager(_dataProvider, ConnectionString);

    db.MappingSchema = new aq2DefaultMappingSchema();

    return db;

}

 

I do this in a using:

 

using (DbManager db = GetDbManager())
{
}

 

Normally I am simply passing the db variable to my GetAccessor<> method calls to reuse the same DbManager.  I seldom make any direct calls to the DbManager.

 

Did I miss something important?

 

Thanks again,

 

Bryan

 

From: Igor Tkachev [mailto:i...@bltoolkit.net]
Sent: Thursday, August 02, 2012 12:03
To: Bryan Ellis
Cc: blto...@googlegroups.com
Subject: Re: [bltoolkit] Possible SQL Server connection leak in BLToolkit

 

Hello, Bryan.

Reply all
Reply to author
Forward
0 new messages