The .NET SDK allows you to create multiple isolated sessions within a single connection. Each session maintains its own namespace, database, variables, and authentication state, while sharing the underlying connection to SurrealDB. This is useful when different parts of your application need to operate under different credentials or contexts simultaneously.
| Method | Description |
|---|---|
db.Sessions()
| List all active sessions on the current connection. |
db.CreateSession()
| Create a new isolated session on the current connection. |
session.ForkSession()
| Creates a copy of a session, inheriting its state. |
session.CloseSession()
| Closes the current session and disposes of it. After this method is called, the session cannot be used again. |
.Sessions()
Returns a list of all active sessions on the current connection.
Arguments
| Arguments | Description |
|---|---|
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.CreateSession()
Creates a new isolated session on the current connection. The new session is independent and maintains its own namespace, database, variables, and authentication state.
Arguments
| Arguments | Description |
|---|---|
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.ForkSession()
Creates a copy of the current session, inheriting its namespace, database, variables, and authentication state. Changes made in the forked session do not affect the original.
Arguments
| Arguments | Description |
|---|---|
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.CloseSession()
Closes the current session and disposes of it. After this method is called, the session cannot be used again.
Note
Arguments
| Arguments | Description |
|---|---|
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |