我正在使用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.
如果我遵循FAQ中的建议(AllResultTypesAreUnknown=true),我可以得到一个字符串,但为什么不能得到一个int?
昨天,这对我来说很好,但我无法找出发生了什么变化或损坏了什么,因此无法设置或获取任何数据类型。我已经删除并重新创建了服务器,运气不好。重新安装了C#驱动程序,也不走运。这是一个简化的代码示例,上面发生在我的带有参数化值和检索结果的“real”代码中。