如何在cassandraemon中将凭据传递给cassandracontext?

ohfgkhjo  于 2021-06-15  发布在  Cassandra
关注(0)|答案(1)|浏览(298)

我正在尝试使用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) 线路。我把字典弄错了吗?密钥不是用户名,密码不是值吗?

slmsl1lt

slmsl1lt1#

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

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

相关问题