4
votes

In connection to the database I use a pool of connections and Firebird database. I use FirebirdSql.Data.FirebirdClient version 2.6.5.0. I have the following connection string:

<add name="db" connectionString="Server=***;user   
id=***;password=***;Charset=ANSI_CHARSET;Database=***;
Connection lifetime=15;Pooling=true;MinPoolSize=0;MaxPoolSize=10" 
providerName="FirebirdSql.Data.FirebirdClient" />

I have the following code that uses the connection to the database:

IEnumerable<Orders> ord = new List<Orders>();
using(FbConnection fbCon = new FbConnection("my connection string"))
{
    fbCon.Open();
    using(FbCommand command = fbCon.CreateCommand())
    {
        command.CommandText = "SELECT first 100 ID, SYMBOL, NUMBER, POS FROM Z1";
        Debug.WriteLine(string.Format("Before Close: {0}", FirebirdSql.Data.FirebirdClient.FbConnection.GetPooledConnectionCount(fbCon)));
        ord= command.ExecuteReader(CommandBehavior.CloseConnection).ConvertToList<Orders>();
    }
}

However, I receive error:

Timeout exceeded.
at FirebirdSql.Data.FirebirdClient.FbConnectionPool.CheckMaxPoolSize ()
at FirebirdSql.Data.FirebirdClient.FbConnectionPool.CheckOut ()
at FirebirdSql.Data.FirebirdClient.FbConnection.Open ()

Error is caused by reaching MaxPoolSize ... every time when I call the above code, in the Output window I ancillary message:

Before Close: 1
Before Close: 2
...
Before Close: 10
2
Have you tried version 4.1.0.0? - Mark Rotteveel
When I used version 4.1.0.0, I got similar error "Connection pool is full". - Bartłomiej Pach
You are not disposing your FBCommand, that probably prevents the connection from getting clean-up as well. - Hans Passant
I changed code that disposing FBCommand, but I still have the same error. - Bartłomiej Pach
I don't see a loop here so how can you have more than one message in output? Provide a real code. - cincura.net

2 Answers

1
votes

Your code may lead to an exception and never reach the Close(), thus leaving the connection open, which could lead to having too many connections open.

You may want to try implementing a Using() in your code.

Here is an article that describes this in more detail.

I had a similar problem with reaching Max connections and the Using() did help.

0
votes

Try using recycling your connection pool in iis. You can set it to reset every 60 minutes or so. This would certainly fix your issue.