Skip to content

Quick start

Oleg V. Kozlyuk edited this page Nov 3, 2022 · 3 revisions
  1. Create new console application
  2. Install ClickHouse.Client package: dotnet add ClickHouse.Client or Install-Package ClickHouse.Client
  3. Paste following code into Program.cs:
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=my.clickhouse;Protocol=https;Port=12345;Username=user");
        // ExecuteScalarAsync is an async extension which creates command and executes it
        var version = await connection.ExecuteScalarAsync("SELECT version()");
        Console.WriteLine(version);
    }
}

Example with Dapper:

using System;
using System.Threading.Tasks;
using ClickHouse.Client.ADO;
using Dapper;

namespace Clickhouse.Test;

class Program
{
    static async Task Main(string[] args)
    {
        using var connection = new ClickHouseConnection("Host=my.clickhouse");
        string sql = "SELECT * FROM system.table_functions";
        var functions = await connection.QueryAsync<string>(sql);
        Console.WriteLine(string.Join('\n', functions));
    }
}
Clone this wiki locally