# Google Cloud Spanner v1 API - Class SessionPool (5.13.0-beta07)

5.13.0-beta07 5.13.0-beta06 5.12.0 (latest) 5.11.0 5.10.0 5.9.0 5.8.0 5.7.0 5.6.0 5.5.0 5.4.0 5.3.0 5.2.0 5.1.0 5.0.0 4.6.0 4.5.0 4.4.0 4.3.0 4.2.0 4.1.0 4.0.0 3.15.1 3.14.0 3.13.0 3.12.0 3.11.0 3.10.0 3.9.0 3.8.0 3.7.0 3.6.0 3.5.0

    public sealed class SessionPool

Reference documentation and code samples for the Google Cloud Spanner v1 API class SessionPool.

A pool of sessions associated with a SpannerClient.
Sessions can be acquired by specifying the desired transaction options, if any.
A session/transaction pair is then returned, which should be returned to the pool when
it is no longer required. Sessions are kept alive automatically, and retired if they
are expired by the server.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> SessionPool

## Inherited Members

[object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Cloud.Spanner.V1](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1)

## Assembly

Google.Cloud.Spanner.V1.dll

## Constructors

### SessionPool(SpannerClient, SessionPoolOptions)

    public SessionPool(SpannerClient client, SessionPoolOptions options)

Creates a session pool for the given client.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `client` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SpannerClient` The client to use for this session pool. Must not be null. |
| `options` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolOptions` The options for this session pool. Must not be null. |

## Properties

### Options

    public SessionPoolOptions Options { get; }

The options governing this session pool.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolOptions` |   |

## Methods

### AcquireDetachedSessionAsync(SessionPoolSegmentKey, TransactionOptions, bool, CancellationToken)

    public Task<PooledSession> AcquireDetachedSessionAsync(SessionPool.SessionPoolSegmentKey key, TransactionOptions transactionOptions, bool singleUseTransaction, CancellationToken cancellationToken)

Asynchronously acquires a session using the given [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey).
The session is detached from the session pool before being returned by this method.
This session pool won't track the acquired session, which won't be returned to be pool even when released.
The session will handle transaction creation as needed.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey` The [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey) to acquire the session. |
| `transactionOptions` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions` The transaction options required for the session. After the operation completes, this value is no longer used, so modifications to the object will not affect the transaction. May be null. |
| `singleUseTransaction` | `https://learn.microsoft.com/dotnet/api/system.boolean` Whether the transaction used by this session is single use or not. May only be true if `transactionOptions` is [ReadOnly](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions.ModeOneofCase#Google_Cloud_Spanner_V1_TransactionOptions_ModeOneofCase_ReadOnly). |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` An optional token for canceling the call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession` | The [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) representing the client, session and, eventually, the transaction. |

### AcquireSessionAsync(DatabaseName, TransactionOptions, CancellationToken)

    public Task<PooledSession> AcquireSessionAsync(DatabaseName databaseName, TransactionOptions transactionOptions, CancellationToken cancellationToken)

Asynchronously acquires a session that will handle transaction creation as needed.
This is equivalent to calling [AcquireSessionAsync(SessionPoolSegmentKey, TransactionOptions, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool#Google_Cloud_Spanner_V1_SessionPool_AcquireSessionAsync_Google_Cloud_Spanner_V1_SessionPool_SessionPoolSegmentKey_Google_Cloud_Spanner_V1_TransactionOptions_System_Threading_CancellationToken_)
passing a segment key with a null database role.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `databaseName` | `Google.Cloud.Spanner.Common.V1.DatabaseName` The name of the database to acquire the session for. |
| `transactionOptions` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions` The transaction options required for the session. After the operation completes, this value is no longer used, so modifications to the object will not affect the transaction. May be null. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` An optional token for canceling the call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession` | The [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) representing the client, session and, eventually, the transaction. |

### AcquireSessionAsync(SessionPoolSegmentKey, TransactionOptions, bool, CancellationToken)

    public Task<PooledSession> AcquireSessionAsync(SessionPool.SessionPoolSegmentKey key, TransactionOptions transactionOptions, bool singleUseTransaction, CancellationToken cancellationToken)

Asynchronously acquires a session using the given [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey).
The session will handle transaction creation as needed.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey` The [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey) to acquire the session. |
| `transactionOptions` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions` The transaction options required for the session. After the operation completes, this value is no longer used, so modifications to the object will not affect the transaction. May be null. |
| `singleUseTransaction` | `https://learn.microsoft.com/dotnet/api/system.boolean` Whether the transaction used by this session is single use or not. May only be true if `transactionOptions` is [ReadOnly](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions.ModeOneofCase#Google_Cloud_Spanner_V1_TransactionOptions_ModeOneofCase_ReadOnly). |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` An optional token for canceling the call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession` | The [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) representing the client, session and, eventually, the transaction. |

### AcquireSessionAsync(SessionPoolSegmentKey, TransactionOptions, CancellationToken)

    public Task<PooledSession> AcquireSessionAsync(SessionPool.SessionPoolSegmentKey key, TransactionOptions transactionOptions, CancellationToken cancellationToken)

Asynchronously acquires a session, using the given [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey).
The session will handle transaction creation as needed.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey` The [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey) to acquire the session. |
| `transactionOptions` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions` The transaction options required for the session. After the operation completes, this value is no longer used, so modifications to the object will not affect the transaction. May be null. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` An optional token for canceling the call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession` | The [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) representing the client, session and, eventually, the transaction. |

### BatchWriteAsync(BatchWriteRequest, SessionPoolSegmentKey, CallSettings)

    [Obsolete("Use ManagedSession.BatchWriteAsync instead.")]
    public Task<AsyncResponseStream<BatchWriteResponse>> BatchWriteAsync(BatchWriteRequest request, SessionPool.SessionPoolSegmentKey key, CallSettings callSettings)

Executes a BatchWrite RPC asynchronously, returning a stream of responses.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.BatchWriteRequest` The batch write request. Must not be null. |
| `key` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey` The session pool segment key. Must not be null. |
| `callSettings` | `https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.CallSettings.html` If not null, applies overrides to this RPC call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task-1https://cloud.google.com/dotnet/docs/reference/Google.Api.Gax/latest/Google.Api.Gax.Grpc.AsyncResponseStream-1.htmlhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.BatchWriteResponse` | A task representing the asynchronous operation. When the task completes, the result is the response stream of [BatchWriteResponse](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.BatchWriteResponse) objects. |

### CreateDetachedSession(SessionName, ByteString, ModeOneofCase)

    public PooledSession CreateDetachedSession(SessionName sessionName, ByteString transactionId, TransactionOptions.ModeOneofCase transactionMode)

Creates a [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) with a known name and transaction ID/mode, with the client associated
with this pool, but is otherwise not part of this pool. This method does not query the server for the session state.
When the returned [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) is released, it will not become part of this pool, and the transaction
will not be rolled back.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `sessionName` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionName` The name of the transaction. Must not be null. |
| `transactionId` | `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html` The ID of the transaction. Must not be null. |
| `transactionMode` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptionshttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions.ModeOneofCase` The mode of the transaction. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession` | A [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) for the given session and transaction. |

**Remarks** This is typically used for partitioned queries, where the same session is used across multiple machines, so should
not be reused by the pool.

### CreateDetachedSession(SessionName, ByteString, ModeOneofCase, Timestamp)

    public PooledSession CreateDetachedSession(SessionName sessionName, ByteString transactionId, TransactionOptions.ModeOneofCase transactionMode, Timestamp readTimestamp)

Creates a [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) with a known name and transaction ID/mode, with the client associated
with this pool, but is otherwise not part of this pool. This method does not query the server for the session state.
When the returned [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) is released, it will not become part of this pool, and the transaction
will not be rolled back.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `sessionName` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionName` The name of the transaction. Must not be null. |
| `transactionId` | `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.ByteString.html` The ID of the transaction. Must not be null. |
| `transactionMode` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptionshttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.TransactionOptions.ModeOneofCase` The mode of the transaction. |
| `readTimestamp` | `https://cloud.google.com/dotnet/docs/reference/Google.Protobuf/latest/Google.Protobuf.WellKnownTypes.Timestamp.html` The read timestamp of the transaction. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession` | A [PooledSession](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.PooledSession) for the given session and transaction. |

**Remarks** This is typically used for partitioned queries, where the same session is used across multiple machines, so should
not be reused by the pool.

### GetSegmentStatisticsSnapshot(DatabaseName)

    [Obsolete("The session pool now relies on multiplexed sessions, which support multiple transactions. There's no need for session pooling and these statistics are meaningless.")]
    public SessionPool.SessionPoolSegmentStatistics GetSegmentStatisticsSnapshot(DatabaseName databaseName)

Provides a snapshot of statistics for the pool associated with the given database.
This is equivalent to calling [GetSegmentStatisticsSnapshot(SessionPoolSegmentKey)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool#Google_Cloud_Spanner_V1_SessionPool_GetSegmentStatisticsSnapshot_Google_Cloud_Spanner_V1_SessionPool_SessionPoolSegmentKey_) passing a segment key
with a null database role.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `databaseName` | `Google.Cloud.Spanner.Common.V1.DatabaseName` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentStatistics` | A snapshot of statistics for this pool. |

### GetSegmentStatisticsSnapshot(SessionPoolSegmentKey)

    [Obsolete("The session pool now relies on multiplexed sessions, which support multiple transactions. There's no need for session pooling and these statistics are meaningless.")]
    public SessionPool.SessionPoolSegmentStatistics GetSegmentStatisticsSnapshot(SessionPool.SessionPoolSegmentKey key)

Provides a snapshot of statistics for the pool associated with the given [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey).

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey` |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentStatistics` | A snapshot of statistics for this pool. |

### GetStatisticsSnapshot()

    [Obsolete("The session pool now relies on multiplexed sessions, which support multiple transactions. There's no need for session pooling and these statistics are meaningless.")]
    public SessionPool.Statistics GetStatisticsSnapshot()

Provides a snapshot of statistics for this pool.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.Statistics` | A snapshot of statistics for this pool. |

### ShutdownPoolAsync(DatabaseName, CancellationToken)

    public Task ShutdownPoolAsync(DatabaseName databaseName, CancellationToken cancellationToken)

Shuts down the session pool associated with the given database name.
Further attempts to acquire sessions will fail immediately.
This is equivalent to calling [ShutdownPoolAsync(SessionPoolSegmentKey, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool#Google_Cloud_Spanner_V1_SessionPool_ShutdownPoolAsync_Google_Cloud_Spanner_V1_SessionPool_SessionPoolSegmentKey_System_Threading_CancellationToken_) passing a segment key
with a null database role.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `databaseName` | `Google.Cloud.Spanner.Common.V1.DatabaseName` The database whose session pool should be shut down. Must not be null. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` An optional token for canceling the returned task. This does not cancel the shutdown itself. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A task which will complete when the session pool has finished shutting down. |

**Remarks** This call will delete all pooled sessions, and wait for all active sessions to be released back to the pool
and also deleted.

### ShutdownPoolAsync(SessionPoolSegmentKey, CancellationToken)

    public Task ShutdownPoolAsync(SessionPool.SessionPoolSegmentKey key, CancellationToken cancellationToken)

Shuts down the session pool of the given SessionPoolSegmentKey.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey` The [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey) whose session pool should be shutdown. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` An optional token for canceling the returned task. This does not cancel the shutdown itself. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A task which will complete when the session pool has finished shutting down. |

**Remarks** This call will delete all pooled sessions, and wait for all active sessions to be released back to the pool
and also deleted.

### WhenPoolReady(DatabaseName, CancellationToken)

    public Task WhenPoolReady(DatabaseName databaseName, CancellationToken cancellationToken = default)

Returns a task indicating when the session pool associated with the given database name is populated up to its minimum size.
This is equivalent to calling [WhenPoolReady(SessionPoolSegmentKey, CancellationToken)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool#Google_Cloud_Spanner_V1_SessionPool_WhenPoolReady_Google_Cloud_Spanner_V1_SessionPool_SessionPoolSegmentKey_System_Threading_CancellationToken_) passing a segment key
with a null database role.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `databaseName` | `Google.Cloud.Spanner.Common.V1.DatabaseName` The database whose session pool should be populated. Must not be null. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` An optional token for canceling the call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A task which will complete when the session pool has reached its minimum size. |

**Remarks** If the pool is unhealthy or becomes unhealthy before it reaches its minimum size,
the returned task will be faulted with an [RpcException](https://cloud.google.com/dotnet/docs/reference/Grpc.Core/latest/Grpc.Core.RpcException.html).

### WhenPoolReady(SessionPoolSegmentKey, CancellationToken)

    public Task WhenPoolReady(SessionPool.SessionPoolSegmentKey key, CancellationToken cancellationToken = default)

Returns a task indicating when the session pool for the given [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey) is populated up to its minimum size.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `key` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPoolhttps://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey` The [SessionPool.SessionPoolSegmentKey](https://docs.cloud.google.com/dotnet/docs/reference/Google.Cloud.Spanner.V1/latest/Google.Cloud.Spanner.V1.SessionPool.SessionPoolSegmentKey) whose session pool should be populated. |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` An optional token for canceling the call. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` | A task which will complete when the session pool has reached its minimum size. |

**Remarks** If the pool is unhealthy or becomes unhealthy before it reaches its minimum size,
the returned task will be faulted with an [RpcException](https://cloud.google.com/dotnet/docs/reference/Grpc.Core/latest/Grpc.Core.RpcException.html).