Migrating the C# driver to connect with Astra databases

Migrate your existing DataStax C# driver to a version compatible with Cassandra databases.

Complete the following procedure to migrate your existing DataStax C# driver to a version that is capable of connecting to Astra databases created using DataStax Astra on Google Cloud.

Prerequisites

  1. Create a DataStax Astra database.
  2. Download the secure connect bundle to obtain connection credentials for your DataStax Astra database.

Procedure

  1. Add the dependencies for the C# driver to your project.
    • DataStax C# driver for Apache Cassandra

      dotnet add package CassandraCSharpDriver -v 3.12.0
    • DSE C# driver

      dotnet add package Dse -v 2.9.0
  2. In your existing DataStax C# driver code, modify the connection code to use the DataStax Astra on Google Cloud API.
    Note: Include the absolute path to the secure connect bundle for your Cassandra database (secure-connect-database_name.zip) in the WithCloudSecureConnectionBundle method call, and your credentials in the WithCredentials method call, as shown in the following examples.
    • DataStax C# driver for Apache Cassandra

      var session = 
        Cluster.Builder()
            .WithCloudSecureConnectionBundle(@"C:\path\to\secure-connect-database_name.zip")
            .WithCredentials("username", "password")
            .Build()
            .Connect();
    • DSE C# driver

      var session = 
        DseCluster.Builder()
            .WithCloudSecureConnectionBundle(@"C:\path\to\secure-connect-database_name.zip")
            .WithCredentials("username", "password")
            .Build()
            .Connect();
  3. Run your application.