ADO.NET provider for QuickBooks Online implements connection pooling to reduce the efforts of repeatedly opening and closing connections. A connection pool is a cache of database connections maintained where 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 supports pooling, by default with the pool size set to 100. However, pooling can be disabled by setting the UsePool property to false.
The following code demonstrates the implementation of connection pooling in ADO.NET provider for QuickBooks Online.
C# |
コードのコピー
|
---|---|
// 接続プーリングを使用する場合: プーリングからの既存の接続を再利用することで時間を節約します。 Console.WriteLine("Estabilishing connection setting Pooling to True"); Console.WriteLine("Estabilishing connection setting Pooling to True"); for (int i = 0; i < 1000; i++) { C1QuickBooksOnlineConnection conn = new C1QuickBooksOnlineConnection($@"{connectionString};Use Pool=true;"); conn.Open();//ソフトな接続が構築されます。 // 操作を実行します。 conn.Close();//接続は接続プールに返されます。 } Console.WriteLine("Connections established and closed !!! "); |
The following example demonstrates how to disable connection pooling by setting the "Use Pool" property to false in the connection string.
C# |
コードのコピー
|
---|---|
//接続プーリングを使用しない場合: Console.WriteLine("Estabilishing connection setting Pooling to False"); for (int i = 0; i < 1000; i++) { C1QuickBooksOnlineConnection conn = new C1QuickBooksOnlineConnection($@"{connectionString};Use Pool=false;"); //By default pooling is true conn.Open();//毎回新しい接続が作成されます。 // 操作を実行します。 conn.Close();//接続オブジェクトはガベージ コレクションに移動されました。 } Console.WriteLine("Connections established and closed !!! "); |