---
title: "ADO.NET data provider"
description: "Use CoraDB from C# and .NET 8 with CoraDB.Data, a fully managed ADO.NET provider: connect, query, transactions, graph queries and migration."
url: "https://www.coradb.ai/manual/api/adodotnet.html"
markdown_url: "https://www.coradb.ai/manual/markdown/api/adodotnet.md"
product: "CoraDB"
version: "1.0"
keywords: "coradb ado.net, coradb .net, coradb c#, CoraDB.Data, CoraDBConnection, ado.net provider, dotnet database driver"
---

# ADO.NET data provider

**CoraDB.Data** is the ADO.NET provider for CoraDB. It implements the CoraDB broker protocol in **100% managed C#**: there is no native library and no P/Invoke, so the same assembly runs on Windows, Linux and macOS. It is a port of the CUBRID ADO.NET provider, which called the native CCI library.

It covers the standard ADO.NET surface — `DbConnection`, `DbCommand`, `DbDataReader`, `DbTransaction`, `DbDataAdapter`, `DbCommandBuilder`, `DbProviderFactory`, `GetSchema` — plus CoraDB extras: several brokers (alternative hosts) with load balancing, batch execution, typed parameters, LOBs, OIDs and collections, query cancel and timeouts, generated keys and query plans.

- Namespace: `CoraDB.Data.CoraDBClient`; assembly: `CoraDB.Data`; target: **.NET 8** (`net8.0`).
- Every CoraDB data type, including the time-zone types (`TIMESTAMPTZ/LTZ`, `DATETIMETZ/LTZ`), ENUM, JSON, SET / MULTISET / LIST, BLOB / CLOB and OBJECT (OID).

## Install

Build the provider with the .NET 8 SDK and reference it from your project:

```powershell
dotnet build CoraDB.Data.sln -c Release
# then, in your project, either reference the project:
#   <ProjectReference Include="..\coradb-NET\src\CoraDB.Data\CoraDB.Data.csproj" />
# or pack it and add the package:
dotnet pack src/CoraDB.Data/CoraDB.Data.csproj -c Release -o artifacts
dotnet add <your project> package CoraDB.Data --source ./artifacts
```

To use it through `DbProviderFactories`, register it once at startup:

```csharp
DbProviderFactories.RegisterFactory(CoraDBClientFactory.InvariantName, CoraDBClientFactory.Instance);
```

## Connect

```csharp
using CoraDB.Data.CoraDBClient;

using var conn = new CoraDBConnection("server=localhost;port=33000;database=e-commerce;user=dba;password=");
conn.Open();
Console.WriteLine(conn.ServerVersion);
```

### Connection string

`key=value;` pairs; keywords are case-insensitive and synonyms are accepted. An empty value (`key=`) keeps the default. The JDBC/CCI URL form also works: `cci:coradb:host:port:db:user:password:?key=value&key=value`. Build strings safely with `CoraDBConnectionStringBuilder`.

| Keyword (synonyms) | Default | Meaning |
|---|---|---|
| `server` (`host`, `data source`) | `localhost` | Broker host, or a list `h1,h2:30001,[::1]:33000` |
| `port` | `33000` | Broker port for hosts without one |
| `database` (`db`, `initial catalog`) | Required | Database name |
| `user` (`uid`, `user id`) | `public` | User name |
| `password` (`pwd`) | Empty | Password |
| `charset` (`encoding`) | `utf-8` | Connection character set |
| `autocommit` | `true` | Auto-commit mode |
| `althosts` | — | Alternative brokers `host:port,host:port`, tried after the main hosts |
| `loadbalance` | `false` | Shuffle the host list on connect |
| `maxConnectionRetryCount` | `1` | Extra rounds over the host list when connecting fails |
| `connectionTimeout` (`connect timeout`) | `30` | Connect timeout, in seconds |
| `loginTimeout` | — | Connect timeout, in milliseconds (JDBC style) |
| `queryTimeout` | `0` | Default `CommandTimeout`, in seconds; when not set, commands use 30 |
| `readTimeout` | `0` | Socket read timeout, in seconds (0 = none) |
| `usessl` | `false` | Connect to an SSL broker (`SSL=ON`) |
| `sslValidateCertificate` (`validateCertificate`) | `false` | Validate the broker's TLS certificate |
| `persistSecurityInfo` | `false` | Keep the password in `ConnectionString` after `Open()` |
| `isolationLevel` | server | `read committed`, `repeatable read`, `serializable` |
| `lockTimeout` | server | Lock timeout in ms (`-1` = infinite) |
| `holdCursors` | `true` | Readers survive commits (holdable result sets) |
| `zeroDateTimeBehavior` | `convertToNull` | How `0000-00-00` is read: `convertToNull`, `round`, `exception` |
| `enforceOldQueryProtocol` | `false` | Use PREPARE + EXECUTE instead of PREPARE_AND_EXECUTE |
| `disconnectOnQueryTimeout` | `false` | Close the connection when a query times out |
| `logSlowQueries`, `slowQueryThresholdMillis` | `false`, `60000` | Log slow queries |
| `logTraceApi`, `logTraceNetwork`, `logFile`, `logBaseDir` | `false` | Driver tracing |

## Run queries

Parameters can be positional (`?`) or named (`?name` / `@name`); markers inside string literals, quoted identifiers and comments are ignored.

```csharp
using (var cmd = new CoraDBCommand(
    "SELECT name, unit_price FROM product WHERE unit_price > ?min ORDER BY unit_price DESC LIMIT 3", conn))
{
    cmd.Parameters.AddWithValue("?min", 90m);
    using var reader = cmd.ExecuteReader();
    while (reader.Read())
        Console.WriteLine($"{reader.GetString(0)}: {reader.GetDecimal(1)}");
}
```

A [graph query](https://www.coradb.ai/manual/graph/match.html) is an ordinary command:

```csharp
using var cmd = new CoraDBCommand(@"
    SELECT b.name AS brand, COUNT(cu) AS followers
    FROM MATCH (cu:customer)-[:follows]->(b:brand)
    GROUP BY b.name ORDER BY followers DESC LIMIT ?", conn);
cmd.Parameters.AddPositional(3);
using var reader = cmd.ExecuteReader();
while (reader.Read())
    Console.WriteLine($"{reader["brand"]}: {reader["followers"]}");   // Nike: 209, Adidas: 132, Puma: 94
```

Helper methods on the connection cover the common cases in one line:

```csharp
int changed = conn.Execute("UPDATE product SET units_in_stock = ? WHERE id = ?", 25, 1379);
List<Dictionary<string, object>> rows = conn.QueryAllAsObjects("SELECT code, name FROM countries ORDER BY name");
DataTable table = conn.QueryToDataTable("SELECT * FROM orders WHERE shipped_date IS NULL");
string plan = conn.GetQueryPlanOnly("SELECT * FROM orders WHERE order_date >= DATE'2025-12-01'");
```

`DbDataAdapter` / `DbCommandBuilder` work as in any ADO.NET provider (`CoraDBDataAdapter`, `CoraDBCommandBuilder`).

## Transactions

```csharp
using (var tx = conn.BeginTransaction())
{
    conn.Execute("INSERT INTO orders (id, customer_id, order_date, shipping_cost, ship_address) VALUES (?, ?, SYSDATE, ?, ?)",
                 9001, 5, 4.90m, "Storgatan 1, Luleå");
    tx.Save("lines");
    conn.Execute("INSERT INTO order_items (order_id, product_id, quantity, discount_pct) VALUES (?, ?, ?, 0)", 9001, 1379, 2);
    // tx.Rollback("lines");
    tx.Commit();
}
```

Commands created from the connection join its pending transaction. Isolation levels: `ReadCommitted`, `RepeatableRead`, `Serializable`; `conn.LockTimeout` sets the lock wait timeout.

## Batches

```csharp
// many statements in one request
CoraDBBatchResult batch = conn.BatchExecute(new[] {
    "UPDATE product SET units_in_stock = units_in_stock + 10 WHERE id = 1379",
    "UPDATE product SET units_in_stock = units_in_stock + 5 WHERE id = 1224" });

// one statement, many parameter rows in one request: CoraDBCommand.ExecuteArray(...)
```

## Errors

Errors are `CoraDBException`. `ErrorCode` is a driver code (`ER_*`, `-21001…`), a CAS code (`CAS_ER_*`, `-10000…`) or the server error number (for example `-493` syntax error, `-670` unique violation).

```csharp
try
{
    conn.Execute("INSERT INTO countries (code, name) VALUES (?, ?)", "FRA", "France");
}
catch (CoraDBException ex)
{
    Console.WriteLine($"[{ex.ErrorCode}] {ex.Message}");
}
```

When the connection breaks outside a transaction, the next request reconnects; a statement that may already have run (INSERT, UPDATE, COMMIT …) is never repeated. Inside a transaction the connection state becomes `Broken`: close it and open it again.

## Migrating from the CUBRID ADO.NET provider

- Replace the `CUBRID.Data` reference with `CoraDB.Data`, and the namespace `CUBRID.Data.CUBRIDClient` with `CoraDB.Data.CoraDBClient`.
- Rename the classes: `CUBRIDConnection` → `CoraDBConnection`, `CUBRIDCommand` → `CoraDBCommand`, `CUBRIDDataReader` → `CoraDBDataReader`, `CUBRIDException` → `CoraDBException`, and so on.
- Remove the native CCI DLLs from the deployment: they are no longer used.
- The `*Async` methods inherited from ADO.NET run synchronously; use `Task.Run` to keep a UI thread free.

## API reference

Every class, method and property — connection, command, parameters, data reader, transaction, adapter, command builder, factory, LOBs, OIDs, batch results, schema provider, errors, loggers and the type mapping — is in the [ADO.NET data provider API reference](https://www.coradb.ai/manual/api/adodotnet-api.html).
