DataConnector | ComponentOne
ADO.NET provider for Magento / Connection Pooling
In This Topic
    Connection Pooling
    In This Topic

    The ADO.NET provider for Magento implements connection pooling to reduce the efforts of repeatedly opening and closing connections. A connection pool is a cache of database connections maintained where the user can reuse existing active connections with the same connection string instead of creating new connections when a request is made to the database.

    Connection pools are used to enhance the performance of executing commands on a database. The provider by default supports pooling as the UsePool property is set to True. However, pooling can be disabled by setting the UsePool property to False.

    The following example demonstrates the implementation of connection pooling in the ADO.NET provider for Magento.

    C#
    Copy Code
    //Define connection string
    
    string connectionString= $"Url='http://***.***.***.***;Consumer Key='*************';Consumer Secret='***********';Verifier='****************'“;
    
    //With Connection Pooling: It saves time by reusing existing connection objects from the pool
    for (int i = 0; i < 1000; i++)
    {
        C1MagentoConnection connection = new C1MagentoConnection ($@"{connectionString};Use Pool=true;");
       connection .Open(); //Soft connections are build
        //Perform Your Operation  
        connection .Close();//Close the connection (returns the connection object to the connection pool)
    }

    The following example demonstrates how to disable connection pooling by setting the "Use Pool" property to false in the connection string.

    C#
    Copy Code
    //Without Connection Pooling
    Console.WriteLine("Establishing connection setting UsePool to false");
    for (int i = 0; i < 1000; i++)
    {
        C1MagentoConnection conn = new C1MagentoConnection ($@"{connectionString};Use Pool=false;");
        conn.Open();//A new connection is created each time
        //Perform Your Operation  
        conn.Close();//Close the connection (Connection object moved to garbage collection)
    }
    Console.WriteLine("Connections established and closed !!! ");