c#控制台应用程序是否尝试连接到aws cassandra服务?

dohp0rv5  于 2021-06-10  发布在  Cassandra
关注(0)|答案(1)|浏览(350)

我使用c#cassandra驱动程序尝试通过控制台应用程序连接到aws cassandra服务(Cassandra司机:https://github.com/datastax/csharp-driver)我还下载了amazonrootca1.pem并将其导入根文件夹
但每次我尝试连接时,都会因为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");
            }

有人能帮我一下我做错了什么吗?
非常感谢你。

a9wyjsp7

a9wyjsp71#

试试下面的例子

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

相关问题