# Connection Pooling

## Content



The ADO.NET provider for Salesforce 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](/componentone/api/services/online-dataconnector/dotnet-standard-api/C1.DataConnector/C1.DataConnector.C1ConnectionStringBuilder.UsePool.html) property is set to **True**. However, pooling can be disabled by setting thethe **UsePool** property to **False**.

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

```csharp
//Define connection string
string GCSalesforceServerConnectionString = @"Username=**********;Password=***********;Security Token=************;
                                            OAuth Client Id=***********;OAuth Client Secret=***************;
                                            OAuth Token Endpoint=https://ap16.salesforce.com/services/oauth2/token;
                                            Url=https://ap16.salesforce.com/services/data/v45.0";
//With Connection Pooling: It saves time by reusing existing connection objects from the pool
for (int i = 0; i < 1000; i++)
{
    C1SalesforceConnection c = new C1SalesforceConnection($@"{GCSalesforceServerConnectionString};Use Pool=true;");
    c.Open();//Soft connections are build
    //Perform Your Operation  
    c.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.

```csharp
//Define connection string
string GCSalesforceServerConnectionString = @"Username=**********;Password=***********;Security Token=************;
                                            OAuth Client Id=***********;OAuth Client Secret=***************;
                                            OAuth Token Endpoint=https://ap16.salesforce.com/services/oauth2/token;
                                            Url=https://ap16.salesforce.com/services/data/v45.0";
//Establish individual connections without connection pooling
for (int i = 0; i < 1000; i++)
{
    C1SalesforceConnection c = new C1SalesforceConnection($@"{GCSalesforceServerConnectionString};Use Pool=false;");
    c.Open();//A new connection is created each time
    //Perform Your Operation  
    c.Close();//Close the connection (Connection object moved to garbage collection)
}
```