### Full ClickHouse Connection String Example Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md A comprehensive example demonstrating various configuration options available in a ClickHouse connection string. ```text Host=hostname;Port=9000;Database=dbname;User=username;Password=password;ReadWriteTimeout=10000;CommandTimeout=15;Compress=true;ClientName=MyApp;TlsMode=Require;ParametersMode=Binary;BufferSize=4096;ClientVersion=1.0.0 ``` -------------------------------- ### Full ClickHouseCommand Usage Example Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseCommand.md A comprehensive example showcasing various functionalities of ClickHouseCommand, including simple queries, parameterized queries with reader, INSERT statements, and integration with external table providers. ```csharp using var conn = new ClickHouseConnection("Host=127.0.0.1;Database=default"); await conn.OpenAsync(); // Simple query using (var cmd = conn.CreateCommand("SELECT COUNT(*) FROM users")) { var count = await cmd.ExecuteScalarAsync(CancellationToken.None); Console.WriteLine($"Total users: {count}"); } // Query with parameters using (var cmd = conn.CreateCommand("SELECT id, name FROM users WHERE id = {userId}")) { cmd.Parameters.AddWithValue("userId", 123); cmd.CommandTimeout = 30; using var reader = await cmd.ExecuteReaderAsync(CancellationToken.None); while (await reader.ReadAsync()) { var id = reader.GetInt32(0); var name = reader.GetString(1); Console.WriteLine($"{id}: {name}"); } } // INSERT with parameters using (var cmd = conn.CreateCommand( "INSERT INTO users(id, name, email) VALUES ({id}, {name}, {email})")) { cmd.Parameters.AddWithValue("id", 999); cmd.Parameters.AddWithValue("name", "NewUser"); cmd.Parameters.AddWithValue("email", "user@example.com"); int affected = await cmd.ExecuteNonQueryAsync(CancellationToken.None); Console.WriteLine($"Inserted {affected} row(s)"); } // With external table var tableProvider = new ClickHouseTableProvider( "external_table", new[] { "id", "value" }, new[] { typeof(int), typeof(string) }, new object[] { new[] { 1, 2, 3 }, new[] { "a", "b", "c" } }); using (var cmd = conn.CreateCommand( "SELECT * FROM external_table WHERE id > {minId}")) { cmd.TableProviders.Add(tableProvider); cmd.Parameters.AddWithValue("minId", 1); using var reader = await cmd.ExecuteReaderAsync(CancellationToken.None); while (await reader.ReadAsync()) { // Process results } } ``` -------------------------------- ### Add ClickHouseClient NuGet Package Source: https://github.com/octonica/clickhouseclient/blob/master/README.md Install the ClickHouseClient package using the .NET CLI. ```bash dotnet add package Octonica.ClickHouseClient ``` -------------------------------- ### Install Octonica.ClickHouseClient Package Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Use this command to add the Octonica.ClickHouseClient package to your .NET project. ```bash dotnet add package Octonica.ClickHouseClient ``` -------------------------------- ### Full Usage Example with ClickHouseConnection Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Demonstrates creating a connection using a connection string, opening it asynchronously, retrieving server information, executing a scalar query, and performing a bulk insert using ColumnWriter. ```csharp // Create connection with connection string var sb = new ClickHouseConnectionStringBuilder { Host = "127.0.0.1", Port = 9000, Database = "default", User = "default", Password = "password" }; using (var conn = new ClickHouseConnection(sb)) { // Open connection asynchronously await conn.OpenAsync(CancellationToken.None); // Check server info var serverInfo = conn.ServerInfo; Console.WriteLine($"Connected to {serverInfo.Name} v{serverInfo.Version}"); // Execute a simple query using (var cmd = conn.CreateCommand("SELECT currentUser()")) { var user = await cmd.ExecuteScalarAsync(); Console.WriteLine($"Current user: {user}"); } // Bulk insert with column writer var ids = Enumerable.Range(1, 1000).ToList(); var names = ids.Select(i => $"Name_{i}").ToList(); using (var writer = await conn.CreateColumnWriterAsync( "INSERT INTO my_table(id, name) VALUES", CancellationToken.None)) { await writer.WriteTableAsync(new object[] { ids, names }, ids.Count, CancellationToken.None); } } ``` -------------------------------- ### Parse Connection String Example Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Demonstrates how to initialize a ClickHouseConnectionStringBuilder by parsing a connection string. This is useful for setting up initial connection parameters. ```csharp var builder = new ClickHouseConnectionStringBuilder( "Host=clickhouse.example.com;Port=9000;Database=analytics;User=admin;Password=secret"); ``` -------------------------------- ### Full ClickHouse Connection String Usage Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Demonstrates parsing a connection string, setting properties individually, building settings, creating a connection, and modifying the connection string dynamically. Includes examples of various configuration options. ```csharp // Method 1: Parse connection string var builder = new ClickHouseConnectionStringBuilder( "Host=clickhouse.example.com;Port=9000;Database=analytics;User=admin;Password=secret"); // Method 2: Set properties individually var builder = new ClickHouseConnectionStringBuilder { Host = "clickhouse.example.com", Port = 9000, Database = "analytics", User = "admin", Password = "secret", ReadWriteTimeout = 20000, CommandTimeout = 30, Compress = true, ClientName = "MyAnalyticsApp", TlsMode = ClickHouseTlsMode.Require, ParametersMode = ClickHouseParameterMode.Binary }; // Build settings var settings = builder.BuildSettings(); // Create and use connection using var conn = new ClickHouseConnection(builder); await conn.OpenAsync(); Console.WriteLine($"Connected to {conn.ServerVersion}"); // Modify connection string builder.Host = "failover.example.com"; conn.ConnectionString = builder.ConnectionString; // Read back as connection string Console.WriteLine(builder.ConnectionString); // Output: Host=failover.example.com;Port=9000;Database=analytics;User=admin;Password=secret;ReadWriteTimeout=20000;... ``` -------------------------------- ### Implement Connection Pooling with ADO.NET Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/configuration.md Demonstrates how to manage ClickHouse connections using ADO.NET patterns for implementing connection pooling. This example shows creating a connection, opening it, and executing a simple query to count users. Consider using external pooling solutions for production environments. ```csharp var connectionString = "Host=clickhouse.example.com;Database=analytics"; // Create connections as needed; consider external pooling (e.g., via dependency injection) public async Task GetUserCountAsync(string connectionString) { using var conn = new ClickHouseConnection(connectionString); await conn.OpenAsync(); using var cmd = conn.CreateCommand("SELECT COUNT(*) FROM users"); var result = await cmd.ExecuteScalarAsync(); return (int)result; ``` -------------------------------- ### ClickHouse Connection String with TLS Enabled Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Example of a connection string configured for secure communication using TLS. ```text Host=secure-clickhouse.example.com;TlsMode=Require;Database=analytics ``` -------------------------------- ### Full Usage Example of ClickHouseDataReader Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Demonstrates comprehensive usage of ClickHouseDataReader, including command creation with parameters, reading basic reader state, retrieving column information, iterating through rows with type-specific getters, and handling multiple result sets. Use this for a complete understanding of data retrieval operations. ```csharp using var cmd = conn.CreateCommand( @"SELECT id, username, email, created_at, is_active FROM users WHERE created_at > {startDate}"); cmd.Parameters.AddWithValue("startDate", new DateTime(2024, 1, 1)); using var reader = await cmd.ExecuteReaderAsync(CancellationToken.None); // Check basic reader state Console.WriteLine($"Field count: {reader.FieldCount}"); Console.WriteLine($"Has rows: {reader.HasRows}"); // Get column information for (int i = 0; i < reader.FieldCount; i++) { var name = reader.GetName(i); var type = reader.GetDataTypeName(i); Console.WriteLine($"Column {i}: {name} ({type})"); } // Read rows while (await reader.ReadAsync()) { int id = reader.GetInt32(0); string username = reader.GetString(1); string email = reader.IsDBNull(2) ? null : reader.GetString(2); DateTime createdAt = reader.GetDateTime(3); bool isActive = reader.GetBoolean(4); Console.WriteLine($"{id}: {username} - {email} (created {createdAt}, active: {isActive})"); } Console.WriteLine($"Total affected rows: {reader.RecordsAffected}"); Console.WriteLine($"Execution progress: {reader.ExecutionProgress}"); // Move to next result set if query returned multiple result sets if (await reader.NextResultAsync()) { while (await reader.ReadAsync()) { // Process next result set } } await reader.CloseAsync(); ``` -------------------------------- ### Set and Get Connection String Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the connection string as a single string in Key=Value format. Individual properties can also be set and then read back as a formatted connection string. ```csharp var builder = new ClickHouseConnectionStringBuilder(); builder.ConnectionString = "Host=localhost;Port=9000;Database=default;Password=mypass"; // Or set individual properties builder.Host = "localhost"; builder.Port = 9000; builder.Database = "default"; builder.Password = "mypass"; // And read back as a connection string string connStr = builder.ConnectionString; ``` -------------------------------- ### ClientVersion Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the client version. Only the major and minor parts are sent to the server. ```APIDOC ## ClientVersion ### Description Gets or sets the client version. | Aspect | Value | |--------|-------| | Type | `ClickHouseVersion` | | Default | Assembly version | | Remarks | Major and minor parts sent to server; build is not sent | ``` -------------------------------- ### ClickHouseParameter Usage Examples Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseParameter.md Demonstrates various ways to create and use ClickHouseParameter objects, including automatic type inference, explicit type setting, timezone handling, precision/scale for decimals, fixed-size strings, nullable parameters, and integration with SQL commands. ```csharp var param1 = new ClickHouseParameter("id", 42); ``` ```csharp var param2 = new ClickHouseParameter("count", ClickHouseDbType.Int32, 100); ``` ```csharp var param3 = new ClickHouseParameter("created_at", new DateTime(2024, 1, 15)); param3.TimeZone = TimeZoneInfo.FindSystemTimeZoneById("UTC"); ``` ```csharp var param4 = new ClickHouseParameter("price", ClickHouseDbType.Decimal); param4.Precision = 18; param4.Scale = 4; param4.Value = 1234.5678m; ``` ```csharp var param5 = new ClickHouseParameter("code", ClickHouseDbType.StringFixedLength, 10); param5.Value = "ABC123"; ``` ```csharp var param6 = new ClickHouseParameter("optional", "value"); param6.IsNullable = true; ``` ```csharp using var cmd = conn.CreateCommand( @"INSERT INTO users(id, name, email, created_at, balance) VALUES ({id}, {name}, {email}, {created_at}, {balance})"); cmd.Parameters.Add(new ClickHouseParameter("id", 1)); cmd.Parameters.Add(new ClickHouseParameter("name", "Alice")); cmd.Parameters.Add(new ClickHouseParameter("email", "alice@example.com")); cmd.Parameters.Add(new ClickHouseParameter("created_at", DateTime.Now)); var balanceParam = new ClickHouseParameter("balance", ClickHouseDbType.Decimal); balanceParam.Precision = 18; balanceParam.Scale = 2; balanceParam.Value = 1000.00m; cmd.Parameters.Add(balanceParam); int affected = await cmd.ExecuteNonQueryAsync(); Console.WriteLine($"Inserted {affected} row(s)"); ``` ```csharp var paramA = new ClickHouseParameter("value", ClickHouseDbType.String); paramA.Value = "original"; var paramB = (ClickHouseParameter)paramA.Clone(); paramB.Value = "modified"; ``` ```csharp var param = new ClickHouseParameter("userInput", "initial"); using var cmd = conn.CreateCommand("SELECT * FROM users WHERE name = {userInput}"); cmd.Parameters.Add(param); param.Value = "Alice"; using var reader1 = await cmd.ExecuteReaderAsync(); param.Value = "Bob"; using var reader2 = await cmd.ExecuteReaderAsync(); ``` -------------------------------- ### CommitAsync Example for ClickHouseColumnWriter Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseColumnWriter.md Shows how to complete a manual transaction after writing all rows using CommitAsync. This is required when using ClickHouseTransactionMode.Manual. ```csharp var writer = await conn.CreateColumnWriterAsync( "INSERT INTO users(id, name) VALUES", CancellationToken.None); for (int i = 0; i < 1000; i++) { await writer.WriteAsync(new object[] { i, $"User_{i}" }, CancellationToken.None); } await writer.CommitAsync(CancellationToken.None); ``` -------------------------------- ### WriteAsync Example for ClickHouseColumnWriter Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseColumnWriter.md Demonstrates how to write individual rows asynchronously to ClickHouse using the WriteAsync method. Ensure the array length matches the FieldCount. ```csharp await writer.WriteAsync( new object[] { i, $"User_{i}", $("user{i}@example.com") }, CancellationToken.None); ``` -------------------------------- ### Create Empty ClickHouseConnectionStringBuilder Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Creates a new empty builder with default values. Use this when starting a new connection string configuration. ```csharp public ClickHouseConnectionStringBuilder() ``` -------------------------------- ### Create Empty ClickHouseCommand Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseCommand.md Instantiates a new ClickHouseCommand without any associated connection or command text. Use this as a starting point before configuring the command. ```csharp public ClickHouseCommand() ``` -------------------------------- ### Get GUID Column Value Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves the Globally Unique Identifier (GUID) value of a specified column. Use this for columns storing UUIDs. ```csharp public override Guid GetGuid(int ordinal) ``` -------------------------------- ### Get Bytes from Column into Buffer Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Reads a specified number of bytes from a binary column into a buffer, starting at given offsets. This is useful for handling large binary data efficiently. It returns the actual number of bytes read. ```csharp public override long GetBytes(int ordinal, long dataOffset, byte[] buffer, int bufferOffset, int length) ``` -------------------------------- ### Get Characters from Column into Buffer Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Reads a specified number of characters from a string column into a character buffer, starting at given offsets. This method is efficient for processing large string data. It returns the actual number of characters read. ```csharp public override long GetChars(int ordinal, long dataOffset, char[] buffer, int bufferOffset, int length) ``` -------------------------------- ### Check for NULL Value Example Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Example demonstrating how to use IsDBNull to check for a NULL value and retrieve the string if it's not NULL. This is useful for handling potential nulls gracefully. ```csharp if (reader.IsDBNull(0)) { Console.WriteLine("Value is NULL"); } else { var value = reader.GetString(0); } ``` -------------------------------- ### Prepare() Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseCommand.md Prepares the command for execution. This is a no-op in ClickHouse client for ADO.NET compatibility. ```APIDOC ## Prepare() ### Description Prepares the command for execution. This is a no-op in ClickHouse client. ### Method Synchronous ### Remarks ClickHouse does not support query preparation, but this method exists for ADO.NET compatibility. ``` -------------------------------- ### Basic ClickHouse Operations with C# Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Demonstrates creating a connection, executing a scalar query, and performing a bulk insert using the Octonica.ClickHouseClient library. Ensure ClickHouse is running and accessible. ```csharp // Create connection var conn = new ClickHouseConnection("Host=localhost;Database=default"); await conn.OpenAsync(); // Execute query using var cmd = conn.CreateCommand("SELECT COUNT(*) FROM users"); var count = await cmd.ExecuteScalarAsync(); Console.WriteLine($"Total users: {count}"); // Bulk insert using var writer = await conn.CreateColumnWriterAsync( "INSERT INTO users(id, name) VALUES", CancellationToken.None); var ids = new List { 1, 2, 3 }; var names = new List { "Alice", "Bob", "Charlie" }; await writer.WriteTableAsync(new object[] { ids, names }, 3, CancellationToken.None); ``` -------------------------------- ### Column Configuration with ConfigureColumn Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseColumnWriter.md Demonstrates how to configure specific columns before writing data, using the ConfigureColumn method. This allows for fine-grained control over column settings. ```csharp await using (var writer = await conn.CreateColumnWriterAsync( "INSERT INTO users(id, name, email) VALUES", CancellationToken.None)) { // Configure specific column var nameSettings = new ClickHouseColumnSettings(); // Apply settings as needed writer.ConfigureColumn("name", nameSettings); var ids = new List { 200, 201 }; var names = new List { "Frank", "Grace" }; var emails = new List { "frank@example.com", "grace@example.com" }; await writer.WriteTableAsync( new object[] { ids, names, emails }, rowCount: 2, CancellationToken.None); } ``` -------------------------------- ### GetName(int ordinal) Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Gets the name of the column at the specified ordinal. ```APIDOC ## GetName(int ordinal) ### Description Gets the name of the column at the specified ordinal. ### Method `GetName(int ordinal)` ### Parameters #### Path Parameters - **ordinal** (`int`) - Required - Zero-based column index ### Return `string` - Column name ``` -------------------------------- ### GetFieldType(int ordinal) Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Gets the .NET Type for the column value at the specified ordinal. ```APIDOC ## GetFieldType(int ordinal) ### Description Gets the .NET `Type` for the column value. ### Method `GetFieldType(int ordinal)` ### Parameters #### Path Parameters - **ordinal** (`int`) - Required - Zero-based column index ### Return `Type` - CLR `Type` for this column ### Example ```csharp Type fieldType = reader.GetFieldType(0); // typeof(string) ``` ``` -------------------------------- ### Configure Query Execution Options in C# Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Illustrates setting command timeout, enabling extreme value calculation, and controlling profile data inclusion. ```csharp cmd.CommandTimeout = 60; // Seconds cmd.CommandTimeoutSpan = TimeSpan.FromMinutes(1); cmd.Extremes = true; // Calculate column extremes cmd.IgnoreProfileEvents = false; // Include profile data ``` -------------------------------- ### GetDataTypeName(int ordinal) Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Gets the ClickHouse type name for the column at the specified ordinal. ```APIDOC ## GetDataTypeName(int ordinal) ### Description Gets the ClickHouse type name for the column. ### Method `GetDataTypeName(int ordinal)` ### Parameters #### Path Parameters - **ordinal** (`int`) - Required - Zero-based column index ### Return `string` - ClickHouse type string (e.g., "String", "Int32", "Array(Int64)") ### Example ```csharp string typeName = reader.GetDataTypeName(0); // "Nullable(String)" ``` ``` -------------------------------- ### User Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the username for authentication. This property is required for authenticated connections. ```APIDOC ## User ### Description Gets or sets the username for authentication. | Aspect | Value | |--------|-------| | Type | `string` | | Default | "default" | | Remarks | Required for authentication | ``` -------------------------------- ### Execute Simple SQL Queries in C# Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Demonstrates executing scalar, non-query, and reader queries. Ensure proper disposal of command and reader objects. ```csharp // ExecuteScalar (first column, first row) using var cmd = conn.CreateCommand("SELECT COUNT(*) FROM users"); var count = await cmd.ExecuteScalarAsync(); ``` ```csharp // ExecuteNonQuery (INSERT/UPDATE/DELETE) using var cmd = conn.CreateCommand("INSERT INTO table VALUES (...)"); int affected = await cmd.ExecuteNonQueryAsync(); ``` ```csharp // ExecuteReader (multiple rows) using var cmd = conn.CreateCommand("SELECT * FROM users"); using var reader = await cmd.ExecuteReaderAsync(); while (await reader.ReadAsync()) { // Process row } ``` -------------------------------- ### Get Column Name by Ordinal Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseColumnWriter.md Retrieves the name of a column using its zero-based ordinal index. ```csharp public string GetName(int ordinal) ``` -------------------------------- ### Configure Protocol and Security Settings Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/configuration.md Control compression, TLS mode, and parameter passing mode for secure and efficient communication. ```csharp public class ClickHouseConnectionStringBuilder { public bool Compress { get; set; } // Default: true public ClickHouseTlsMode TlsMode { get; set; } // Default: Disable public ClickHouseParameterMode ParametersMode { get; set; } // Default: Default (Binary) } ``` ```csharp builder.Compress = true; // Enable LZ4 builder.TlsMode = ClickHouseTlsMode.Require; // Require TLS builder.ParametersMode = ClickHouseParameterMode.Binary; // Safe parameter passing ``` -------------------------------- ### SslMode Property (Deprecated) Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the SSL mode. This property is deprecated and TlsMode should be used instead. ```APIDOC ## SslMode ### Description Gets or sets the SSL mode (deprecated; use TlsMode instead). | Aspect | Value | |--------|-------| | Type | `ClickHouseSslMode?` | | Default | `null` | | Remarks | Legacy property; TlsMode is preferred | ``` -------------------------------- ### CommandTimeout Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the command execution timeout in seconds. This value is used as the default for ClickHouseCommand.CommandTimeout. ```APIDOC ## CommandTimeout ### Description Gets or sets the command execution timeout. | Aspect | Value | |--------|-------| | Type | `int` | | Default | 15 | | Unit | Seconds | | Remarks | Used as default for ClickHouseCommand.CommandTimeout | ``` -------------------------------- ### Configuring ClickHouse Parameter Modes Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Shows how to set the default parameter mode for a connection or override it for a specific command. Binary is the default, Interpolate works anywhere but is less efficient, and Serialize requires server support. ```csharp // Set connection-level mode builder.ParametersMode = ClickHouseParameterMode.Binary; // Override per-command cmd.ParametersMode = ClickHouseParameterMode.Interpolate; ``` -------------------------------- ### Password Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the password for authentication. This property is optional and can be null or empty for unauthenticated connections. ```APIDOC ## Password ### Description Gets or sets the password for authentication. | Aspect | Value | |--------|-------| | Type | `string?` | | Default | `null` | | Remarks | Optional; null/empty for unauthenticated connections | ``` -------------------------------- ### High-Performance Configuration String Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/configuration.md Optimize for high performance with settings like timeouts, buffer size, and compression. ```text Host=clickhouse-cluster.internal;Port=9000;Database=events;User=etl;Password=pass;ReadWriteTimeout=30000;CommandTimeout=60;BufferSize=16384;Compress=true;ParametersMode=Binary ``` -------------------------------- ### Demonstrating Parameter Naming Styles Source: https://github.com/octonica/clickhouseclient/blob/master/docs/Parameters.md This snippet shows how to use different parameter naming styles, including the default {name:dataType}, the simplified {name}, and the MSSQL-like @name format within a ClickHouseCommand. ```C# using var connection = new ClickHouseConnection(connectionStr); connection.Open(); var cmd = connection.CreateCommand("SELECT number/{value:Decimal64(2)} FROM numbers(100000) WHERE number >= @min AND number <= {max}"); cmd.Parameters.AddWithValue("value", 100); cmd.Parameters.AddWithValue("{min}", 1000); cmd.Parameters.AddWithValue("@max", 2000); using var reader = cmd.ExecuteReader(); while(reader.Read()) { // Reading the data } ``` -------------------------------- ### Manual Transaction Control with WriteRowsAsync and CommitAsync Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseColumnWriter.md Illustrates how to manage transactions manually using WriteRowsAsync and CommitAsync. This allows for batching inserts and explicit commit operations. ```csharp await using (var writer = await conn.CreateColumnWriterAsync( "INSERT INTO users(id, name, email) VALUES", CancellationToken.None)) { writer.MaxBlockSize = 500; // Write multiple batches for (int batch = 0; batch < 10; batch++) { var batchIds = new List(); var batchNames = new List(); var batchEmails = new List(); for (int i = 0; i < 100; i++) { int id = batch * 100 + i + 100; batchIds.Add(id); batchNames.Add($"User_{id}"); batchEmails.Add($"user{id}@example.com"); } await writer.WriteRowsAsync( new object[] { batchIds, batchNames, batchEmails }, rowCount: 100, transactionMode: ClickHouseTransactionMode.Manual, CancellationToken.None); } // Commit all transactions await writer.CommitAsync(CancellationToken.None); } ``` -------------------------------- ### Get Decimal Column Value Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves the decimal value of a specified column. Use this for precise decimal arithmetic. ```csharp public override decimal GetDecimal(int ordinal) ``` -------------------------------- ### Development Configuration String Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/configuration.md Settings suitable for a development environment, including specific timeouts and compression settings. ```text Host=localhost;Port=9000;Database=development;User=dev;Password=dev_password;CommandTimeout=30;Compress=false ``` -------------------------------- ### GetOrdinal(string name) Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Gets the zero-based column ordinal by name. Throws IndexOutOfRangeException if the column name is not found. ```APIDOC ## GetOrdinal(string name) ### Description Gets the zero-based column ordinal by name. ### Method `GetOrdinal(string name)` ### Parameters #### Path Parameters - **name** (`string`) - Required - Column name ### Return `int` - Zero-based ordinal ### Throws `IndexOutOfRangeException` - If column name is not found ### Example ```csharp int nameIndex = reader.GetOrdinal("name"); string name = reader.GetString(nameIndex); ``` ``` -------------------------------- ### ClientName Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the name of the client application. This name is sent to the server as part of client identification. ```APIDOC ## ClientName ### Description Gets or sets the name of the client application. | Aspect | Value | |--------|-------| | Type | `string` | | Default | "Octonica.ClickHouseClient" | | Remarks | Sent to server as part of client identification | ``` -------------------------------- ### Development Programmatic Configuration Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/configuration.md Configure development environment settings programmatically in C#. ```csharp var builder = new ClickHouseConnectionStringBuilder { Host = "localhost", Port = 9000, Database = "development", User = "dev", Password = "dev_password", CommandTimeout = 30, Compress = false }; ``` -------------------------------- ### Initialize ClickHouseConnection with settings and type provider Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Initializes a connection with connection settings and an optional custom type provider. Uses the default type provider if null is passed. ```csharp public ClickHouseConnection(ClickHouseConnectionSettings connectionSettings, IClickHouseTypeInfoProvider? typeInfoProvider) ``` -------------------------------- ### ReadWriteTimeout Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the network socket timeout in milliseconds. This timeout is applied to both sending and receiving operations. ```APIDOC ## ReadWriteTimeout ### Description Gets or sets the network socket timeout in milliseconds. | Aspect | Value | |--------|-------| | Type | `int` | | Default | 10000 | | Unit | Milliseconds | | Remarks | Applied to both TcpClient.SendTimeout and ReceiveTimeout | ``` -------------------------------- ### Host Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the hostname or IP address of the ClickHouse server. This property is required for establishing a connection. ```APIDOC ## Host ### Description Gets or sets the hostname or IP address of the ClickHouse server. | Aspect | Value | |--------|-------| | Type | `string?` | | Default | `null` (required) | | Remarks | Must be specified before opening connection | ``` -------------------------------- ### Minimal Local Programmatic Connection Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/configuration.md Configure a minimal local connection using C#. ```csharp var builder = new ClickHouseConnectionStringBuilder { Host = "localhost" }; ``` -------------------------------- ### GetServerTimeZone() - ClickHouseConnection Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Gets the default timezone of the connected ClickHouse server. Ensure the connection is open before calling this method. ```csharp public TimeZoneInfo GetServerTimeZone() ``` ```csharp await conn.OpenAsync(); var tz = conn.GetServerTimeZone(); Console.WriteLine(tz.DisplayName); ``` -------------------------------- ### Build Settings from Builder Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Creates a ClickHouseConnectionSettings object from the current builder values. Throws ArgumentException if required properties like Host are not set. ```csharp var builder = new ClickHouseConnectionStringBuilder { Host = "localhost", Database = "default" }; var settings = builder.BuildSettings(); var conn = new ClickHouseConnection(settings); ``` -------------------------------- ### Create ClickHouseConnection from Settings Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Initialize a ClickHouseConnection using settings built from a ClickHouseConnectionStringBuilder. This is an alternative to passing the builder directly. ```csharp // From settings var settings = builder.BuildSettings(); var conn = new ClickHouseConnection(settings); ``` -------------------------------- ### Initialize ClickHouseConnection with no settings Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Use this constructor when you intend to set the connection string later via the ConnectionString property before opening the connection. ```csharp public ClickHouseConnection() ``` -------------------------------- ### Get Double Column Value Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves the double-precision floating-point value of a specified column. Use this for standard floating-point calculations. ```csharp public override double GetDouble(int ordinal) ``` -------------------------------- ### Get Byte Column Value Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves the byte value of a specified column. Use this for columns storing single-byte data. ```csharp public override byte GetByte(int ordinal) ``` -------------------------------- ### ClickHouseConnection() Constructor Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Initializes an empty ClickHouseConnection with no settings. The connection string must be set via the ConnectionString property before opening. ```APIDOC ## ClickHouseConnection() ### Description Initializes an empty connection with no settings. The connection string must be set via the `ConnectionString` property before opening. ### Parameters None ### Remarks The connection string must be set via the `ConnectionString` property before opening. ``` -------------------------------- ### Database Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the default database name. This property is optional and is used for queries that do not specify a database prefix. ```APIDOC ## Database ### Description Gets or sets the default database name. | Aspect | Value | |--------|-------| | Type | `string?` | | Default | `null` | | Remarks | Optional; queries without db prefix use this | ``` -------------------------------- ### ClickHouseCommand Binary Mode Parameter Usage Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseCommand.md Demonstrates parameter passing in binary mode, which is the default. Parameters are sent as a temporary table with a single row. ```csharp using var cmd = conn.CreateCommand("SELECT * FROM users WHERE id = {id}"); cmd.Parameters.AddWithValue("id", 42); using var reader = cmd.ExecuteReader(); ``` -------------------------------- ### Dapper Integration with ClickHouse Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Use Dapper to query data from ClickHouse. Ensure you have the necessary Dapper and ClickHouseClient packages installed. ```csharp using var conn = new ClickHouseConnection("Host=localhost;Database=default"); conn.Open(); var users = conn.Query("SELECT id, name, email FROM users WHERE active = true"); ``` -------------------------------- ### Load Configuration from Environment Variables Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/configuration.md Configure the ClickHouse client by reading connection details from environment variables. This approach allows for flexible configuration without modifying code. Ensure the necessary environment variables are set before running the application. ```csharp var host = Environment.GetEnvironmentVariable("CLICKHOUSE_HOST") ?? "localhost"; var port = ushort.Parse(Environment.GetEnvironmentVariable("CLICKHOUSE_PORT") ?? "9000"); var database = Environment.GetEnvironmentVariable("CLICKHOUSE_DATABASE") ?? "default"; var user = Environment.GetEnvironmentVariable("CLICKHOUSE_USER") ?? "default"; var password = Environment.GetEnvironmentVariable("CLICKHOUSE_PASSWORD"); var builder = new ClickHouseConnectionStringBuilder { Host = host, Port = port, Database = database, User = user, Password = password }; using var conn = new ClickHouseConnection(builder); await conn.OpenAsync(); ``` -------------------------------- ### Get Single Character from Column Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves the first character of a string value from a specified column. Use this when you only need the initial character. ```csharp public override char GetChar(int ordinal) ``` -------------------------------- ### Open ClickHouseConnection Asynchronously Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Establish a database connection asynchronously using OpenAsync(). This is preferred for non-blocking operations. Overloads are available for specifying a CancellationToken. ```csharp // Asynchronous await conn.OpenAsync(); await conn.OpenAsync(CancellationToken.None); ``` -------------------------------- ### Get Boolean Column Value Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves the boolean value of a specified column. This method will throw an InvalidCastException if the value cannot be converted to a boolean. ```csharp public override bool GetBoolean(int ordinal) ``` -------------------------------- ### Typical ClickHouse Connection String Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md A common connection string configuration including host, database, and password. ```text Host=clickhouse.local;Database=default;Password=mysecure ``` -------------------------------- ### TlsMode Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the TLS/SSL mode for the connection. Supported values are Disable and Require. Use RemoteCertificateValidationCallback for custom validation. ```APIDOC ## TlsMode ### Description Gets or sets the TLS/SSL mode for the connection. | Aspect | Value | |--------|-------| | Type | `ClickHouseTlsMode` | | Default | `Disable` | | Values | `Disable`, `Require` | | Remarks | Use RemoteCertificateValidationCallback for custom certificate validation | ``` -------------------------------- ### Initialize ClickHouseConnection with a connection string builder Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Initializes a connection using a ClickHouseConnectionStringBuilder object, which encapsulates connection settings. ```csharp public ClickHouseConnection(ClickHouseConnectionStringBuilder stringBuilder) ``` -------------------------------- ### Compress Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets a value indicating whether LZ4 compression is enabled for data transfer. Compression is applied in both directions. ```APIDOC ## Compress ### Description Gets or sets whether LZ4 compression is enabled. | Aspect | Value | |--------|-------| | Type | `bool` | | Default | `true` | | Remarks | Compression applied to both client-to-server and server-to-client data | ``` -------------------------------- ### ClickHouseConnection(string connectionString, IClickHouseTypeInfoProvider? typeInfoProvider) Constructor Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Initializes a ClickHouseConnection with a connection string and an optional custom type provider. ```APIDOC ## ClickHouseConnection(string connectionString, IClickHouseTypeInfoProvider? typeInfoProvider) ### Description Initializes a connection with a connection string and custom type provider. ### Parameters #### Path Parameters - **connectionString** (string) - Required - Connection string - **typeInfoProvider** (IClickHouseTypeInfoProvider?) - Optional - Custom type provider; if null, uses default ``` -------------------------------- ### Bulk Insert with WriteTableAsync Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseColumnWriter.md Demonstrates how to perform a bulk insert of multiple rows using the WriteTableAsync method. Ensure the connection and table are set up before use. ```csharp using var conn = new ClickHouseConnection("Host=127.0.0.1;Database=default"); await conn.OpenAsync(); // Create a table using (var cmd = conn.CreateCommand( "CREATE TABLE IF NOT EXISTS users(id Int32, name String, email String)")) { await cmd.ExecuteNonQueryAsync(); } // Bulk insert using WriteTableAsync var ids = new List { 1, 2, 3, 4, 5 }; var names = new List { "Alice", "Bob", "Charlie", "Diana", "Eve" }; var emails = new List { "alice@example.com", "bob@example.com", "charlie@example.com", "diana@example.com", "eve@example.com" }; await using (var writer = await conn.CreateColumnWriterAsync( "INSERT INTO users(id, name, email) VALUES", CancellationToken.None)) { await writer.WriteTableAsync( new object[] { ids, names, emails }, rowCount: 5, CancellationToken.None); } Console.WriteLine("Bulk insert completed"); ``` -------------------------------- ### BufferSize Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the preferred size of the internal buffer used for communication. The actual buffer size may vary. ```APIDOC ## BufferSize ### Description Gets or sets the preferred size of the internal buffer. | Aspect | Value | |--------|-------| | Type | `int` | | Default | 4096 | | Unit | Bytes | | Remarks | Preferred size; actual size may vary | ``` -------------------------------- ### Port Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the port number for the ClickHouse native protocol. The default value is 9000, and the valid range is 1-65535. ```APIDOC ## Port ### Description Gets or sets the port number for the ClickHouse native protocol. | Aspect | Value | |--------|-------| | Type | `ushort` | | Default | `9000` | | Range | 1-65535 | | Remarks | Standard ClickHouse native protocol port | ``` -------------------------------- ### ClickHouseConnection(ClickHouseConnectionSettings connectionSettings, IClickHouseTypeInfoProvider? typeInfoProvider) Constructor Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Initializes a ClickHouseConnection with ClickHouseConnectionSettings and an optional custom type provider. ```APIDOC ## ClickHouseConnection(ClickHouseConnectionSettings connectionSettings, IClickHouseTypeInfoProvider? typeInfoProvider) ### Description Initializes a connection with settings and custom type provider. ### Parameters #### Path Parameters - **connectionSettings** (ClickHouseConnectionSettings) - Required - Connection settings - **typeInfoProvider** (IClickHouseTypeInfoProvider?) - Optional - Custom type provider ``` -------------------------------- ### Get Column Ordinal by Name Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseColumnWriter.md Retrieves the zero-based ordinal (index) of a column given its name. Throws ArgumentException if the column is not found. ```csharp public int GetOrdinal(string name) ``` -------------------------------- ### Define Basic Connection Properties Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/configuration.md Set essential connection properties such as host, port, database, user, and password. ```csharp public class ClickHouseConnectionStringBuilder : DbConnectionStringBuilder { // Essential properties public string? Host { get; set; } public ushort Port { get; set; } public string? Database { get; set; } public string User { get; set; } public string? Password { get; set; } } ``` ```csharp var builder = new ClickHouseConnectionStringBuilder { Host = "clickhouse.example.com", Port = 9000, Database = "analytics", User = "analyst", Password = "secure_password" }; ``` -------------------------------- ### Create ClickHouseConnection from Connection String Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Instantiate a ClickHouseConnection using a connection string. Ensure the connection string includes necessary details like Host and Database. ```csharp // From connection string var conn = new ClickHouseConnection("Host=localhost;Database=default"); ``` -------------------------------- ### Get Int32 Column Value Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves a 32-bit signed integer value from a specified column. This is the standard integer type for many operations. ```csharp public override int GetInt32(int ordinal) ``` -------------------------------- ### ClickHouseConnection(ClickHouseConnectionSettings connectionSettings) Constructor Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Initializes a ClickHouseConnection with ClickHouseConnectionSettings. ```APIDOC ## ClickHouseConnection(ClickHouseConnectionSettings connectionSettings) ### Description Initializes a connection with connection settings. ### Parameters #### Path Parameters - **connectionSettings** (ClickHouseConnectionSettings) - Required - Connection settings object ``` -------------------------------- ### ClickHouseCommand Key Methods Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Highlights key methods for executing SQL commands and retrieving results using ClickHouseCommand. ```APIDOC ## Core Classes | Class | Purpose | Key Methods | |-------|---------|-------------| | `ClickHouseCommand` | SQL query execution | ExecuteReader, ExecuteScalar, ExecuteNonQuery (+ async variants) | ``` -------------------------------- ### Get Int16 Column Value Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves a 16-bit signed integer value from a specified column. Use this for small integer values to save memory. ```csharp public override short GetInt16(int ordinal) ``` -------------------------------- ### Initialize ClickHouseConnection with a connection string Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Initializes a connection using a provided connection string. This constructor uses the default type provider. ```csharp public ClickHouseConnection(string connectionString) ``` -------------------------------- ### Get Float Column Value Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves the single-precision floating-point value of a specified column. Use this when memory or performance is a concern and double precision is not required. ```csharp public override float GetFloat(int ordinal) ``` -------------------------------- ### Open() Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Synchronously opens the connection to the ClickHouse server. This method is used to establish a connection before executing any database operations. ```APIDOC ## Open() ### Description Synchronously opens the connection to the ClickHouse server. ### Method `Open` ### Return `void` ### Throws - `ClickHouseException` with code `ConnectionClosed`: connection already closed - `ClickHouseException` with code `NetworkError`: network connectivity issues - `ClickHouseException` with code `TlsError`: TLS/SSL protocol errors ### Example ```csharp var conn = new ClickHouseConnection("Host=127.0.0.1;Database=default"); conn.Open(); ``` ``` -------------------------------- ### Get Schema Information as DataTable Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves the schema information of the query results as a DataTable object. This can be used to inspect column names, types, and other metadata. ```csharp public override DataTable? GetDataTable() ``` -------------------------------- ### Initialize ClickHouseConnection with connection settings Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Initializes a connection using a ClickHouseConnectionSettings object, providing a structured way to manage connection parameters. ```csharp public ClickHouseConnection(ClickHouseConnectionSettings connectionSettings) ``` -------------------------------- ### Get Column Value as Object Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves the value of a specified column as an object. Use this for generic data retrieval when the specific type is unknown or not critical. ```csharp public override object? GetValue(int ordinal) ``` -------------------------------- ### High-Performance Programmatic Configuration Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/configuration.md Configure high-performance settings programmatically in C#. ```csharp var builder = new ClickHouseConnectionStringBuilder { Host = "clickhouse-cluster.internal", Port = 9000, Database = "events", User = "etl", Password = "pass", ReadWriteTimeout = 30000, CommandTimeout = 60, BufferSize = 16384, Compress = true, ParametersMode = ClickHouseParameterMode.Binary }; ``` -------------------------------- ### Get Int64 Column Value Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieves a 64-bit signed integer value from a specified column. Use this for large integer values that exceed the range of Int32. ```csharp public override long GetInt64(int ordinal) ``` -------------------------------- ### Initialize ClickHouseConnection with builder and type provider Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Initializes a connection using a connection string builder and an optional custom type provider. The default type provider is used if null is provided. ```csharp public ClickHouseConnection(ClickHouseConnectionStringBuilder stringBuilder, IClickHouseTypeInfoProvider? typeInfoProvider) ``` -------------------------------- ### ConnectionString Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets the connection string as a single string. This property allows for easy parsing of existing connection strings or setting a complete connection string at once. ```APIDOC ## ConnectionString (Property) ### Description Gets or sets the connection string as a single string. This property allows for easy parsing of existing connection strings or setting a complete connection string at once. ### Format `Key=Value;Key2=Value2;...` ### Example ```csharp var builder = new ClickHouseConnectionStringBuilder(); builder.ConnectionString = "Host=localhost;Port=9000;Database=default;Password=mypass"; // Or set individual properties builder.Host = "localhost"; builder.Port = 9000; builder.Database = "default"; builder.Password = "mypass"; // And read back as a connection string string connStr = builder.ConnectionString; ``` ``` -------------------------------- ### ClickHouseConnection Opening Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/README.md Shows how to open a ClickHouse connection synchronously or asynchronously. ```APIDOC ## Opening Connections ```csharp // Synchronous conn.Open(); // Asynchronous await conn.OpenAsync(); await conn.OpenAsync(CancellationToken.None); ``` ``` -------------------------------- ### ParametersMode Property Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md Gets or sets how parameters are passed to queries. Binary mode is recommended for security. Supported values include Default, Inherit, Binary, Interpolate, and Serialize. ```APIDOC ## ParametersMode ### Description Gets or sets how parameters are passed to queries. | Aspect | Value | |--------|-------| | Type | `ClickHouseParameterMode` | | Default | `Default` (which is `Binary`) | | Values | `Default`, `Inherit`, `Binary`, `Interpolate`, `Serialize` | | Remarks | Binary mode is recommended for security | ``` -------------------------------- ### CreateCommand(string commandText) Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnection.md Creates and returns a new `ClickHouseCommand` with the specified SQL command text. This allows for immediate creation of a command ready for execution. ```APIDOC ## CreateCommand(string commandText) ### Description Creates and returns a new `ClickHouseCommand` with the specified command text. ### Method `CreateCommand` ### Parameters #### Path Parameters - **commandText** (`string`) - SQL query text ### Return `ClickHouseCommand` with specified command text ### Example ```csharp using var cmd = conn.CreateCommand("SELECT COUNT(*) FROM table"); var count = await cmd.ExecuteScalarAsync(); ``` ``` -------------------------------- ### Bulk Insert Data Source: https://github.com/octonica/clickhouseclient/blob/master/README.md Perform a bulk insert operation into a ClickHouse table. This example first creates a table if it doesn't exist, generates data, and then uses ClickHouseColumnWriterAsync for efficient insertion. ```csharp using var conn = new ClickHouseConnection("Host=127.0.0.1"); conn.Open(); using var cmd = conn.CreateCommand("CREATE TABLE IF NOT EXISTS table_with_two_fields(id Int32, name String) engine Memory"); await cmd.ExecuteNonQueryAsync(); //generate values List ids = Enumerable.Range(1, 10_000).ToList(); List names = ids.Select(i => $"Name #{i}").ToList(); //insert data await using (var writer = await conn.CreateColumnWriterAsync("insert into table_with_two_fields(id, name) values", default)) { await writer.WriteTableAsync(new object[] { ids, names }, ids.Count, default); } ``` -------------------------------- ### Minimal ClickHouse Connection String Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseConnectionStringBuilder.md The most basic connection string requires only the host parameter. ```text Host=localhost ``` -------------------------------- ### Get Data Type Name by Ordinal Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Obtain the ClickHouse-specific data type name for a column using its ordinal index. This can be helpful for understanding the underlying data types stored in ClickHouse. ```csharp string typeName = reader.GetDataTypeName(0); // "Nullable(String)" ``` -------------------------------- ### Get Field Type by Ordinal Source: https://github.com/octonica/clickhouseclient/blob/master/_autodocs/api-reference/ClickHouseDataReader.md Retrieve the .NET CLR Type corresponding to the data type of a column at a given ordinal index. This is useful for casting or working with the data in a strongly-typed manner within your .NET application. ```csharp Type fieldType = reader.GetFieldType(0); // typeof(string) ```