---
type: Development Guide
title: Getting Started with Distributed SQL Transactions in the ScalarDB Cluster .NET Client SDK
description: The ScalarDB Cluster .NET Client SDK supports the distributed SQL transaction functionality of ScalarDB Cluster. The SDK includes transaction and manager abstractions for easier communication within a cluster.
resource: https://scalardb.scalar-labs.com/docs/3.15/scalardb-cluster-dotnet-client-sdk/getting-started-with-distributed-sql-transactions/
tags:
- scalardb
- v3.15
- phase:implement
- section:develop
- edition:enterprise-premium
- unmaintained
status: deprecated
product: scalardb
product_title: ScalarDB
version: '3.15'
patch_version: 3.15.9
doc_id: scalardb-cluster-dotnet-client-sdk/getting-started-with-distributed-sql-transactions
lifecycle_phase: implement
breadcrumb:
- Develop
- Run Transactions
- Reference
- .NET Interface Guides
editions:
- Enterprise Premium
generated:
  by: process:okf-build/1.0.0
  at: '2026-08-04T23:50:56Z'
sources:
- id: docs-scalardb
  resource: https://github.com/scalar-labs/docs-scalardb/blob/6126dfe2f56389351d88b134752618641f9771dd/versioned_docs/version-3.15/scalardb-cluster-dotnet-client-sdk/getting-started-with-distributed-sql-transactions.mdx
  title: ScalarDB documentation source (MDX)
  author: process:scalar-labs/docs-scalardb
  last_modified: '2026-08-04T15:05:02Z'
---

# Getting Started with Distributed SQL Transactions in the ScalarDB Cluster .NET Client SDK

The ScalarDB Cluster .NET Client SDK supports the distributed SQL transaction functionality of ScalarDB Cluster. The SDK includes transaction and manager abstractions for easier communication within a cluster.

:::note

Although we recommend using asynchronous methods, as in the following examples, you can use synchronous methods instead.

:::

For details about distributed non-SQL transactions, see [Getting Started with Distributed Transactions in the ScalarDB Cluster .NET Client SDK](./getting-started-with-distributed-transactions.md).

## Install the SDK

Install the same major and minor version of the [SDK](https://www.nuget.org/packages/ScalarDB.Client) as ScalarDB Cluster into the .NET project. You can do this by using the built-in NuGet package manager, replacing `<MAJOR>.<MINOR>` with the version that you're using:

```console
dotnet add package ScalarDB.Client --version '<MAJOR>.<MINOR>.*'
```

## Create a settings file

Create a `scalardb-options.json` file and add the following, replacing `<HOSTNAME_OR_IP_ADDRESS>` with the FQDN or the IP address, and `<PORT>` with the port number (`60053` by default) of your cluster:

```json
{
  "ScalarDbOptions": {
    "Address": "http://<HOSTNAME_OR_IP_ADDRESS>:<PORT>",
    "HopLimit": 10
  }
}
```

For details about settings files and other ways to configure the client, see [Client configuration](./common-reference.md#client-configuration).

## Get a transaction manager

You need to get a transaction manager object for distributed SQL transactions. To get the transaction manager object, you can use `TransactionFactory` as follows:

```c#
// Pass the path to the settings file created in the previous step.
var factory = TransactionFactory.Create("scalardb-options.json");

using var manager = factory.GetSqlTransactionManager();
```

## Execute SQL queries

To execute a SQL statement, you need an `ISqlStatement` object, which can be created by using a builder as follows:

```c#
using ScalarDB.Client.Builders.Sql;

// ...

var sqlStatement =
    new SqlStatementBuilder()
        .SetSql("SELECT * FROM order_service.statements WHERE item_id = :item_id")
        .AddParam("item_id", 2)
        .Build();
```

A single SQL statement can be executed directly by using the transaction manager as follows:

```c#
var resultSet = await manager.ExecuteAsync(sqlStatement);
```

The result from the `ExecuteAsync` method will contain records received from the cluster. The value of the specific column can be retrieved in the following manner:

```c#
foreach (var record in resultSet.Records)
{
    // Getting an integer value from the "item_id" column.
    // If it fails, an exception will be thrown.
    var itemId = record.GetValue<int>("item_id");

    // Trying to get a string value from the "order_id" column.
    // If it fails, no exception will be thrown.
    if (record.TryGetValue<string>("order_id", out var orderId))
        Console.WriteLine($"order_id: {orderId}");

    // Checking if the "count" column is null.
    if (record.IsNull("count"))
        Console.WriteLine("'count' is null");
}
```

For details about which type should be used in `GetValue<T>` and `TryGetValue<T>`, see [How ScalarDB Column Types Are Converted to and from .NET Types](./common-reference.md#how-scalardb-column-types-are-converted-to-and-from-net-types).

## Execute SQL queries in a transaction

To execute multiple SQL statements as part of a single transaction, you need a transaction object.

You can create a transaction object by using the transaction manager as follows:

```c#
var transaction = await manager.BeginAsync();
```

You can also resume a transaction that has already been started as follows:

```c#
var transaction = manager.Resume(transactionIdString);
```

:::note

The `Resume` method doesn't have an asynchronous version because it only creates a transaction object. Because of this, resuming a transaction by using the wrong ID is possible.

:::

The transaction has the same `ExecuteAsync` method as the transaction manager. That method can be used to execute SQL statements.

When a transaction is ready to be committed, you can call the `CommitAsync` method of the transaction as follows:

```c#
await transaction.CommitAsync();
```

To roll back the transaction, you can use the `RollbackAsync` method:

```c#
await transaction.RollbackAsync();
```

## Get Metadata

You can retrieve ScalarDB's metadata with the Metadata property as follows:

```c#
// namespaces, tables metadata
var namespaceNames = new List<string>();

await foreach (var ns in manager.Metadata.GetNamespacesAsync())
{
    namespaceNames.Add(ns.Name);
    Console.WriteLine($"Namespace: {ns.Name}");

    await foreach (var tbl in ns.GetTablesAsync())
    {
        Console.WriteLine($"  Table: {tbl.Name}");

        Console.WriteLine($"  Columns:");
        foreach (var col in tbl.Columns)
            Console.WriteLine($"    {col.Name} [{col.DataType}]");

        Console.WriteLine($"  PartitionKey:");
        foreach (var col in tbl.PartitionKey)
            Console.WriteLine($"    {col.Name}");

        Console.WriteLine($"  ClusteringKey:");
        foreach (var col in tbl.ClusteringKey)
            Console.WriteLine($"    {col.Name} [{col.ClusteringOrder}]");

        Console.WriteLine($"  Indexes:");
        foreach (var index in tbl.Indexes)
            Console.WriteLine($"    {index.ColumnName}");

        Console.WriteLine();
    }
}

// users metadata
await foreach (var user in manager.Metadata.GetUsersAsync())
{
    Console.WriteLine($"User: {user.Name} [IsSuperuser: {user.IsSuperuser}]");

    foreach (var nsName in namespaceNames)
    {
        Console.WriteLine($"  Namespace: {nsName}");

        Console.WriteLine($"  Privileges:");
        foreach (var privilege in await user.GetPrivilegesAsync(nsName))
            Console.WriteLine($"    {privilege}");
    }

    Console.WriteLine();
}
```

:::note

To use LINQ methods with `IAsyncEnumerable<T>`, you can install [System.Linq.Async](https://www.nuget.org/packages/System.Linq.Async/) package.

:::
