如何将凭据传递给Cassandraemon中的CassandraContext?

时间:2013-05-20 18:41:17

标签: cassandra

我正在尝试使用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)错误。我的凭证字典错了吗?密钥不是用户名而密码不是值吗?

1 个答案:

答案 0 :(得分:0)

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

Dictionary<string, string> credentials = new Dictionary<string, string>();
credentials.Add("username", "yourusernamehere");
credentials.Add("password", "yourpasswordhere");
context.Login(credentials);