Installation

dotnet add package ClickHouse.Client

Examples

Basic query

using System;
using System.Threading.Tasks;
using ClickHouse.Client.ADO;
using ClickHouse.Client.Utility;
namespace Clickhouse.Test;
class Program
{
    static async Task Main(string[] args)
    {
        using var connection = new ClickHouseConnection("Host=<host>;Protocol=https;Port=8443;Username=default;Password=<password>")
        // ExecuteScalarAsync is an async extension which creates command and executes it
        var version = await connection.ExecuteScalarAsync("SELECT version()");
        Console.WriteLine(version);
    }
}

Bulk insert

using var connection = new ClickHouseConnection("Host=<host>;Protocol=https;Port=8443;Username=default;Password=<password>");
using var bulkCopyInterface = new ClickHouseBulkCopy(connection)
{
    DestinationTableName = "<database>.<table>",
    BatchSize = 100000
};
// Example data to insert
var values = Enumerable.Range(0, 1000000).Select(i => new object[] { (long)i, "value" + i.ToString() });
await bulkCopyInterface.WriteToServerAsync(values);
Console.WriteLine(bulkCopyInterface.RowsWritten);

Other integrations

Get started with ClickHouse Cloud for free

We'll get you started on a 30 day trial and $300 credits to spend at your own pace.