プライマリ・コンテンツに移動
Oracle® Data Provider for .NET開発者ガイド
ODAC 12.2c リリース1 (12.2.0.1) for Microsoft Windows
E88311-03
目次へ移動
目次
索引へ移動
索引

前
次

ClearPool

このメソッドでは、指定のOracleConnectionオブジェクトに関連付けられている接続プールがクリアされます。

宣言

// C#
public static void ClearPool(OracleConnection connection);

備考

このメソッドが呼び出されると、すべてのアイドル接続はクローズされプールから解放されます。プールに戻されるまで現在使用中の接続は廃棄されません。

ODP.NET 12cリリース1 (12.1)以降の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!");
  }
}