尝试打开与clickhousedb的连接时程序挂起?

pb3skfrl  于 2021-07-15  发布在  ClickHouse
关注(0)|答案(2)|浏览(655)

我正在尝试从应用程序连接到本地clickhousedb以执行一些原始查询。当我试图打开连接时,问题出现了。它从不从方法调用返回。
clickhousedb是在docker容器中启动的。

using (ClickHouseConnection conn = connFactory.CreateConnection(new ClickHouseConnectionSettings(connectionString)))
            {
                var cmd = conn.CreateCommand();

                cmd.CommandText = "select * from default.table_name";

                conn.Open(); // it never goes past this line
                using (var reader = cmd.ExecuteReader())
                ...

我想在会议结束后开通一个连接 conn.Open() 并继续执行下一行执行读卡器的程序。
注意:如果我尝试从python控制台进行连接,绝对没有问题。

from clickhouse_driver import Client
client = Client(host='localhost')
client.execute('select * from default.table_name')

# [(4, 'four'), (5, 'five'), (1, 'one'), (2, 'two'), (3, 'three')]

更新:连接后stacktrace超时:

System.IO.IOException: Unable to read data from the transport connection: 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. ---> System.Net.Sockets.SocketException: 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
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   --- End of inner exception stack trace ---
   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
   at InhouseNamespace.ClickHouse.Impl.ProtocolFormatter.ReadBytes(Int32 i)
   ...

部署clickhouse的docker compose。我不是dockerMaven,所以我对db很满意,我可以通过tabix web ui连接到它:

version: "3.7"
services:
  clickhouse:
    image: yandex/clickhouse-server
    ports:
    - "8123:8123"
    - "9000:9000"
    - "9009:9009"

    ulimits:
     nproc: 65535
     nofile:
      soft: 262144
      hard: 262144
 client:
    image: yandex/clickhouse-client
    command: ['--host', 'server']

更新:在连接到非本地cassandradb之后,问题消失了,这意味着连接到我的本地cassandradb(在docker容器中)有问题。

lb3vh1jj

lb3vh1jj1#

端口8123用作http接口的默认端口。但在使用时:

conn.Open();
using (var reader = cmd.ExecuteReader())

通信是通过本地clickhouse客户端完成的,因此必须使用端口9000。
要解决此问题,请更改连接字符串中的端口。完整的连接字符串如下所示: connString = "Host=127.0.0.1;Port=9000;User=default;Password=;Database=default;Compress=True;CheckCompressedHash=False;SocketTimeout=60000000;Compressor=lz4"

myss37ts

myss37ts2#

您使用的连接字符串似乎不正确。
取出“port”键并将端口号附加到服务器(您现在已将其命名为“host”)键,如下所示:
“服务器=127.0.0.18123;用户=默认值;密码=;数据库=默认值;压缩=真;checkcompressedhash=假;sockettimeout=60000000;压缩机=lz4“
谢谢,加里

相关问题