ClearPool
このメソッドでは、指定のOracleConnectionオブジェクトに関連付けられている接続プールがクリアされます。
宣言
// C# public static void ClearPool(OracleConnection connection);
備考
このメソッドが呼び出されると、すべてのアイドル接続はクローズされプールから解放されます。プールに戻されるまで現在使用中の接続は廃棄されません。
ClearPoolによって新しい接続はプールに自動的に再移入されません。これは、クライアントからデータベース・サーバーに接続できない状態が続く場合に、無効な接続でプールが再移入されるのを防止するためです。開発者は、OracleConnection.Open()のコールによってプールが再移入されるときのプログラムを制御して、接続数以上の最小プール・サイズを持つプールに再移入することができます。
このメソッドを呼び出した後に作成された接続は、他のメソッドが呼び出されるまではクリアされません。
ConnectionStringが適切に設定されている場合、このメソッドは接続をオープンする前およびオープンした後に、OracleConnectionオブジェクトに対して起動できます。
例外
InvalidOperationException - 接続プールが見つからないか、指定された接続文字列が無効です。
例
// C#
// Sample demonstrating the use of ClearPool API in OracleConnection class
using System;
using Oracle.DataAccess.Client;
class ClearPoolSample
{
static void Main()
{
Console.WriteLine("Running ClearPool sample..." );
// Set the connection string
string strConn = "User Id=scott;Password=tiger;Data Source=oracle;" +
"Min pool size=5;";
OracleConnection conn = new OracleConnection(strConn);
// Open the connection
conn.Open();
// Clears the connection pool associated with connection 'conn'
OracleConnection.ClearPool (conn);
// This connection will be placed back into the pool
conn.Close ();
// Open the connection again to create additional connections in the pool
conn.Open();
// Create a new connection object
OracleConnection connNew = new OracleConnection(strConn);
// Clears the pool associated with Connection 'connNew'
// Since the same connection string is set for both the connections,
// connNew and conn, they will be part of the same connection pool.
// We need not do an Open() on the connection object before calling
// ClearPool
OracleConnection.ClearPool (connNew);
// cleanup
conn.Close();
Console.WriteLine("Done!");
}
}