DataStax Astra Developer Hub

Welcome to the DataStax Astra Developer Hub. You'll find comprehensive guides and documentation to help you start working with DataStax Astra as quickly as possible. Use the included APIs to create, modify, and terminate databases, and interact with the databases you create. Let's do it!

Astra Docs      API Reference      CQL for Astra

DataStax C# driver

Use the unified DataStax C# driver to connect to your DataStax Astra database and begin building your own application.

๐Ÿ“˜

Tip

DataStax recommends using the unified DataStax C# driver. If you have an existing Apache Cassandra or DataStax Enterprise (DSE) C# driver, migrate the driver to a version that is capable of connecting to Astra databases.

Prerequisites

  1. Download and install the current version of the .NET Core SDK.
  2. Download the secure connect bundle to obtain connection credentials for your DataStax Astra databasedatabase - A group of distributed instances for storing data. Each paid Astra database has at least three instances..

๐Ÿ“˜

Tip

Alternatively, have a teammate provide access to their Astra database.

Procedure

  1. Create a new C# project and configure it to connect to your Cassandra database.
mkdir csharpproject
cd csharpproject
dotnet new console
  1. Add the dependencies for the C# driver to your project.
dotnet add package CassandraCSharpDriver -v 3.15.0
  1. Replace the code in Program.cs with the following code to connect to your Astra database.

๐Ÿ“˜

Note

Include the absolute path to the secure connect bundle for your Astra 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.

using System;
using System.Linq;
using Cassandra;

namespace csharpproject
{
    class Program
    {
        static void Main(string[] args)
        {
            var session = 
                Cluster.Builder()
                       .WithCloudSecureConnectionBundle(@"C:\path\to\secure-connect-database_name.zip")
                       .WithCredentials("username", "password")
                       .Build()
                       .Connect();               
        }
    }
}
  1. After the connection code, add the following code to the Main method in Program.cs. This code runs a CQL query, and prints the output to the console.
var rowSet = session.Execute("select * from system.local");
Console.WriteLine(rowSet.First().GetValue<string>("cluster_name"));
  1. Run your C# project with the dotnet runtime.
dotnet restore
dotnet build
dotnet run --no-build

Updated 17 days ago



DataStax C# driver


Use the unified DataStax C# driver to connect to your DataStax Astra database and begin building your own application.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.