【发布时间】:2019-12-21 02:31:52
【问题描述】:
我正在尝试从我的应用程序连接到本地 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')]
更新: ConnectionTimeout 后的堆栈跟踪:
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。我不是 docker 专家,所以我对 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 容器中)时出现问题。
【问题讨论】:
-
如果您等待的时间足够长,您将收到一个异常,该异常应提供有关该问题的更多信息。能否也提供一下连接字符串的样子?
-
connString = "Host=127.0.0.1;Port=8123;User=default;Password=;Database=default;Compress=True;CheckCompressedHash=False;SocketTimeout=60000000;Compressor=lz4"我刚刚注意到socketTimeout,我会减少它,看看会发生什么。 -
是的,超时时间非常高。你也可以发布docker配置吗? ie:你用什么命令来启动容器?
-
我已经发布了docker-compose的内容。我只是打电话给
docker-compose up -
您是否可以尝试更新连接字符串以查看是否是问题所在?
标签: c# docker docker-compose ado.net clickhouse