简体   繁体   中英

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 driver: https://github.com/datastax/csharp-driver ) I also downlaoded the AmazonRootCA1.pem and imported it into the root folder

But everytime i try to connect it fails because of the 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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM