【发布时间】:2018-09-20 07:46:10
【问题描述】:
我正在使用 Npgsql 连接到不安全的本地 CockroachDb 服务器,如下所示:
using (NpgsqlConnection connection = new NpgsqlConnection(@"Port=26257;Username=user;Database=thedata;Host=localhost")) {
connection.Open();
NpgsqlCommand command = new NpgsqlCommand("SELECT 1 AS records", connection);
command.CommandType = CommandType.Text;
using (NpgsqlDataReader reader = command.ExecuteReader()) {
while (reader.Read()) {
Console.WriteLine(reader["records"].GetType());
}
}
}
GetType() 失败并出现异常:
The field 'records' has a type currently unknown to Npgsql (OID 20). You can retrieve it as a string by marking it as unknown, please see the FAQ.
如果我按照常见问题解答 (AllResultTypesAreUnknown=true) 中的建议,我可以获得字符串,但为什么不能获得 int?
昨天,这对我来说工作正常,但我无法弄清楚发生了什么变化或损坏,因此我无法设置或获取任何数据类型。我已经删除并重新创建了服务器,没有运气。重新安装了 C# 驱动程序,也没有运气。这是一个精简的代码示例,上面发生在我的“真实”代码中,带有参数化值以及检索到的结果。
【问题讨论】:
标签: c# npgsql cockroachdb