The msdn docs do state: "The connection pooler removes a connection from
the pool after it has been idle for a long time, *or if the pooler detects
that the connection with the server has been severed*."
So other database providers probably check periodically for broken
connections.

however the docs also say "If a connection exists to a server that has
disappeared, this connection can be drawn from the pool *even if the
connection pooler has not detected the severed connection and marked it as
invalid. *This is the case because the overhead of checking that the
connection is still valid would eliminate the benefits of having a pooler
by causing another round trip to the server to occur. *When this occurs,
the first attempt to use the connection will detect that the connection has
been severed, and an exception is thrown.*"

See attached patch(+ test program) that adds a connection check on idle
connections in the connection pool cleanup code that is run every 2 seconds
to remove old connections.
Even with the patch if the server goes away between checks you can still
get a broken connection as is the case with other database providers.

This does cause a small network request for each idle connection in the
pool every 2 seconds so don't know if this patch would be suitable for
public use.

On Mon, Jan 26, 2015 at 3:32 PM, Luciano Mendes <[email protected]> wrote:

> Let me copy, once again, the source code of the SW that is not work. Note
> the
> I am always open the Polling connection according the documentation (
> https://msdn.microsoft.com/en-us/library/8xx3tyca(v=vs.100).aspx ) and it
> was broken since the version 4.6.0.0:
>
> ===========================
> using FirebirdSql.Data.FirebirdClient;
>
> public static bool ExecuteCommand(string DML)
>         {
>             using (FbConnection fbConnection = new
> FbConnection(connectionString()))
>             using (FbCommand fbCommand = new FbCommand(DML, fbConnection))
>                 try
>                 {
>                     Cursor.Current = Cursors.WaitCursor;
>                     fbCommand.Connection.Open();
>                     fbCommand.ExecuteNonQuery();
>                     return true;
>                 }
>                 catch (FbException ex)
>                 {
>                     return false;
>                 }
>                 finally
>                 {
>                     Cursor.Current = Cursors.Default;
>                 }
>         }
>
>
>
> --
> View this message in context:
> http://firebird.1100200.n4.nabble.com/Error-reading-data-from-the-connection-tp4638893p4638932.html
> Sent from the firebird-net-provider mailing list archive at Nabble.com.
>
>
> ------------------------------------------------------------------------------
> Dive into the World of Parallel Programming. The Go Parallel Website,
> sponsored by Intel and developed in partnership with Slashdot Media, is
> your
> hub for all things parallel software development, from weekly thought
> leadership blogs to news, videos, case studies, tutorials and more. Take a
> look and join the conversation now. http://goparallel.sourceforge.net/
> _______________________________________________
> Firebird-net-provider mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/firebird-net-provider
>



-- 
------------------------------------------------------------------------
Gerdus van Zyl
www.infireal.com
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FirebirdSql.Data.FirebirdClient;
using System.ServiceProcess;

namespace ConnectionPoolTest
{
    class Program
    {

        static void StopFirebirdService()
        {
            var sc = new ServiceController("FirebirdServersifirebird");
            Console.WriteLine("Stopping...");
            sc.Stop();
            sc.WaitForStatus(ServiceControllerStatus.Stopped);
            Console.WriteLine("Stopped");
        }

        static void StartFirebirdService()
        {
            var sc = new ServiceController("FirebirdServersifirebird");
            Console.WriteLine("Starting...");
            sc.Start();
            sc.WaitForStatus(ServiceControllerStatus.Running );
            Console.WriteLine("Started");
        }

        static void Main(string[] args)
        {
            Console.WriteLine("[Connection pool test]");

            var csb = new FbConnectionStringBuilder();
            csb.DataSource = "localhost";
            csb.Port = 55504;
            csb.Database  = "pooltest.fdb";
            csb.UserID = "SYSDBA";
            csb.Password = "masterke";
            csb.Pooling = true;
            csb.MinPoolSize = 0;
            csb.MaxPoolSize = 100;
            csb.ConnectionLifeTime = 500;            

            FbConnection.CreateDatabase(csb.ToString(), true);

            using (var con = new FbConnection(csb.ToString()))
            {
                con.Open();
                using (var trans = con.BeginTransaction())
                {
                    using (var cmd = new FbCommand("select 1 from 
rdb$database", con, trans))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            
            StopFirebirdService();
            System.Threading.Thread.Sleep(5 * 1000);
            StartFirebirdService();

            using (var con = new FbConnection(csb.ToString()))
            {
                con.Open();
                using (var trans = con.BeginTransaction())
                {
                    using (var cmd = new FbCommand("select 1 from 
rdb$database", con, trans))
                    {
                        cmd.ExecuteNonQuery();
                    }
                }
            }
            
            Console.WriteLine("Press the any key...");
            Console.ReadKey();
        }
    }
}

Attachment: FbConnectionPoolManager.patch
Description: Binary data

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Firebird-net-provider mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/firebird-net-provider

Reply via email to