The ADO.NET provider for Google Analytics 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 Google Analytics.
C# |
Copy Code |
---|---|
//Define connection string string connectionString = string.Format("Key File={0};View Id={1}", KeyFile, ViewId); // With Connection Pooling: It saves time by reusing existing connections from the pool for (int i = 0; i < 1000; i++) { C1GoogleAnalyticsConnection conn = new C1GoogleAnalyticsConnection($@"{connectionString};Use Pool=true;"); conn.Open();//Soft connections are build //Perform Your Operation conn.Close();//Connection is returned 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 |
---|---|
//Define connection string string connectionString = string.Format("Key File={0};View Id={1}", KeyFile, ViewId); //Without Connection Pooling for (int i = 0; i < 1000; i++) { C1GoogleAnalyticsConnection conn = new C1GoogleAnalyticsConnection($@"{connectionString};Use Pool=false;");//By default pooling is true conn.Open(); //A new connection is created each time //Perform Your Operation conn.Close();//Connection object is moved to garbage collection } |