Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DKGH opened this issue May 31, 2024 · 3 comments
Open

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

DKGH opened this issue May 31, 2024 · 3 comments

Comments

@DKGH
Copy link

DKGH commented May 31, 2024

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
Copy link
Author

DKGH commented Jul 12, 2024

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

@Enmk
Copy link
Collaborator

Enmk commented Dec 16, 2024

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
Copy link
Collaborator

Enmk commented Dec 16, 2024

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:

SSL_CTX * ssl_context = nullptr;

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants