clickhouse-cpp icon indicating copy to clipboard operation
clickhouse-cpp copied to clipboard

ClientOptions().SetHost("hostname") throws an exception

Open DKGH opened this issue 1 year ago • 3 comments

I ran the sample program listed on the README.md tutorial. However, it throws a system_error exception at line 409 in client.cpp. This is mitigated by entering the right port. Now the exception comes after a long wait and it says operation successful: can't recieve string data: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

I would like to connect to a database and run some select queries on it. How do I do that? I have database host machine name and port, user name, password and table name.

DKGH avatar May 31 '24 06:05 DKGH

This appears to be related to SSL verification within my organization. How do I disable that?

DKGH avatar Jul 12 '24 03:07 DKGH

Hi @DKGH! It looks like you are either trying to connect to SSL port with as a non-ssl client, or vice versa.

to configure a non-ssl connection

auto client_options = ClientOptions()
        .SetHost(server_hostname)
        .SetPort(server_port) // typically  9000
        .SetUser(user_name) // optional
        .SetPassword(password) // optional
        .SetDefaultDatabase(database_name); // optional


to configure an ssl connection:

// almost the same as above, but make sure that you are using correct PORT
auto client_options = ClientOptions()
        .SetHost(server_hostname)
        .SetPort(server_port) // typically  9440 <<<=================!!!!! HERE
        .SetUser(user_name) // optional
        .SetPassword(password) // optional
        .SetDefaultDatabase(database_name); // optional

client_options.SetSSLOptions(
        ClientOptions::SSLOptions()
                    .SetUseDefaultCALocations(true)
                    .SetMaxProtocolVersion(SSL3_VERSION));

And then (regardless of how you've initialized ClientOptions instance, create a client:

auto client_ = std::make_unique<Client>(client_options);

Enmk avatar Dec 16 '24 22:12 Enmk

For configuring SSL connection there is a TON of options: https://github.com/ClickHouse/clickhouse-cpp/blob/master/clickhouse/client.h#L138

But if you have a example that produces proper SSL_CTX*, perhaps it would be easiest to use just that: https://github.com/ClickHouse/clickhouse-cpp/blob/2a49a25b573b1194f621070711440ea125577f50/clickhouse/client.h#L152

Please note that this is a CLIENT context, not a SERVER context

Enmk avatar Dec 16 '24 22:12 Enmk

@DKGH I'm going to close this issue as we've not heard back from you to be able to reproduce the issue. Please reopen if the issue persists

laeg avatar Jul 22 '25 10:07 laeg