OleDbConnection.ReleaseObjectPool Método

Definição

Indica que o pool de objetos OleDbConnection pode ser liberado quando a última conexão subjacente é liberada.Indicates that the OleDbConnection object pool can be released when the last underlying connection is released.

public:
 static void ReleaseObjectPool();
public static void ReleaseObjectPool ();
static member ReleaseObjectPool : unit -> unit
Public Shared Sub ReleaseObjectPool ()

Exemplos

O exemplo a seguir cria um OleDbConnection, abre, exibe algumas de suas propriedades, fecha a conexão e libera o pool de objetos para conservar recursos.The following example creates an OleDbConnection, opens it, displays some of its properties, closes the connection, and releases the object pool to conserve resources.

static void OpenConnection(string connectionString)
{
    using (OleDbConnection connection = new OleDbConnection(connectionString))
    {
        try
        {
            connection.Open();
            Console.WriteLine("Connection.State: {0}", connection.State);

            connection.Close();
            OleDbConnection.ReleaseObjectPool();
            Console.WriteLine("Connection.State: {0}", connection.State);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex.Message);
        }
        // The connection is automatically closed when the
        // code exits the using block.
    }
}
Public Sub OpenConnection(ByVal connectionString As String)

    Using connection As New OleDbConnection(connectionString)
        Try
            connection.Open()
            Console.WriteLine("Connection.State: {0}", _
                connection.State)

            connection.Close()
            OleDbConnection.ReleaseObjectPool()
            Console.WriteLine("Connection.State: {0}", _
                connection.State)

        Catch ex As Exception
            Console.WriteLine(ex.Message)
        End Try
    End Using
End Sub

Comentários

ReleaseObjectPool pode ser chamado para liberar recursos que, de outra forma, seriam reservados para objetos de OleDbConnection em pool.ReleaseObjectPool can be called to free resources that would otherwise be reserved for pooled OleDbConnection objects. Talvez você queira chamar esse método se, por exemplo, o objeto de conexão não for usado novamente durante o tempo em que os serviços de OLE DB normalmente mantêm as conexões em pool ativas.You might want to call this method if, for example, the connection object will not be used again for the amount of time that OLE DB services ordinarily keeps pooled connections active. Observe que chamar o método sozinho não libera de fato as conexões ativas existentes no pool.Note that calling the method alone does not actually release the active connections that exist in the pool.

O seguinte deve ocorrer antes de o pool ser finalmente descartado:The following must occur before the pool is finally disposed:

  1. Chame Close para retornar o objeto de conexão para o pool.Call Close to return the connection object to the pool.

  2. Permita que cada objeto de conexão expire o tempo do pool.Allow each connection object to time out of the pool.

  3. Chame ReleaseObjectPool.Call ReleaseObjectPool.

  4. Invocar coleta de lixo.Invoke garbage collection.

Por outro lado, se você chamar Close em todas as conexões ativas e invocar a coleta de lixo, mas não chamar ReleaseObjectPool, os recursos reservados para os objetos em pool permanecerão disponíveis.Conversely, if you call Close on all active connections, and invoke garbage collection, but do not call ReleaseObjectPool, the resources reserved for the pooled objects will remain available.

Aplica-se a

Veja também