[英]C# console application try to connect to AWS Cassandra Service?
I use the C# cassandra driver to try to connect via a console application to the AWS Cassandra service.我使用 C# cassandra 驱动程序尝试通过控制台应用程序连接到 AWS Cassandra 服务。 (c# cassandra driver: https://github.com/datastax/csharp-driver ) I also downlaoded the AmazonRootCA1.pem and imported it into the root folder (c# cassandra 驱动程序: https : //github.com/datastax/csharp-driver )我也下载了 AmazonRootCA1.pem 并将其导入根文件夹
But everytime i try to connect it fails because of the SSL:但是每次我尝试连接它都会因为 SSL 而失败:
Cluster cluster = Cluster.Builder()
.AddContactPoint("cassandra.us-east-2.amazonaws.com")
.WithPort(9142)
.WithAuthProvider(new PlainTextAuthProvider("LoginName", "Password"))
.WithSSL()
.Build();
var session = cluster.Connect("tutorialkeyspace");
var rs = session.Execute("SELECT * FROM tutorialtable");
foreach (var row in rs)
{
var value = row.GetValue<int>("sample_int_column");
Console.WriteLine("Success");
}
Can someone help me what im doing wrong ?有人可以帮助我我做错了什么吗?
Thank you very much.非常感谢。
Try the following C# example尝试以下 C# 示例
X509Certificate2Collection certCollection = new X509Certificate2Collection();
X509Certificate2 amazoncert = new X509Certificate2(@"path_to_file\AmazonRootCA1.pem");
var userName = "ServiceUserName";
var pwd = "ServicePassword";
certCollection.Add(amazoncert);
var awsEndpoint = "cassandra.us-east-2.amazonaws.com" ;
var cluster = Cluster.Builder()
.AddContactPoints(awsEndpoint)
.WithPort(9142)
.WithAuthProvider(new PlainTextAuthProvider(userName, pwd))
.WithSSL(new SSLOptions().SetCertificateCollection(certCollection))
.Build();
var session = cluster.Connect();
var rs = session.Execute("SELECT * FROM system_schema.tables;");
foreach (var row in rs)
{
var name = row.GetValue<String>("keyspace_name");
Console.WriteLine(name);
}
}
https://docs.aws.amazon.com/keyspaces/latest/devguide/using_dotnetcore_driver.html https://docs.aws.amazon.com/keyspaces/latest/devguide/using_dotnetcore_driver.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.