0

我正在尝试使用 Cassandraemon 连接到 C# .NET 中的 Cassandra 实例。我找不到任何允许您指定凭据的示例。我的 Cassandra 实例在 AWS 的服务器上运行,我需要传递用户名/密码才能连接。我有以下代码:

var builder = new CassandraConnectionConfigBuilder
{
    Hosts = new[] { "cassandra.myinstance.com" },
    ConsistencyLevel = ConsistencyLevel.QUORUM,
    Timeout = TimeSpan.FromSeconds(100),
    Keyspace = "mykeyspace"
};

var config = new CassandraConnectionConfig(builder);
using (var context = new CassandraContext(config))
{
    Dictionary<string, string> credentials = new Dictionary<string, string>();
    credentials.Add("username", "password");
    context.Login(credentials);
}

当我运行它时,我得到一个Apache.Cassandra.AuthenticationException错误context.Login(credentials)。我弄错了凭据字典吗?密钥不是用户名,密码不是值吗?

4

1 回答 1

0

我错误地使用了凭据字典。字典需要提供正确值的“用户名”和“密码”键。以下是正确的代码:

Dictionary<string, string> credentials = new Dictionary<string, string>();
credentials.Add("username", "yourusernamehere");
credentials.Add("password", "yourpasswordhere");
context.Login(credentials);
于 2013-05-20T18:56:00.480 回答