Get a database object (C#)

When using a client, most Data API interactions require you to connect to a database through a DataAPIClient object.

Connecting to a database is an essential component of most Data API client scripts. For more information, see Get started with the Data API (C#).

For more information about the Data API client hierarchy, see Python client internals, TypeScript client internals, Go client internals, Java client internals, and C# client internals.

Result

Returns a Database object that you can use to perform CRUD operations on your database

Parameters

Use the GetDatabase method, which belongs to the DataAPIClient class.

Method signature
public Database GetDatabase(string apiEndpoint);
public Database GetDatabase(
  string apiEndpoint, string token, string keyspace = null
);
public Database GetDatabase(
  string apiEndpoint, GetDatabaseOptions options
);
Name Type Summary

apiEndpoint

string

A database API endpoint URL, such as https://DATABASE_ID-REGION.apps.astra.datastax.com.

token

str

Optional. An application token for a database, in the form of an "AstraCS:…​" string.

The token should have sufficient permissions to perform the desired operations.

If you specified a token when instantiating the DataAPIClient, that token will be overridden.

keyspace

string

Optional. Specify the working keyspace. This keyspace is used for all downstream operations unless you later override it with a method such as useKeyspace, getCollection, createCollection, getTable, or createTable.

Default: default_keyspace

options

GetDatabaseOptions

Optional. General API options for this operation, including the keyspace and timeout. For more information and examples, see Customize API interaction.

Examples

The following examples demonstrate how to connect to a database.

using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;

namespace Examples;

public class Program
{
  static void Main()
  {
    var client = new DataAPIClient();
    var database = client.GetDatabase(
      "API_ENDPOINT",
      "APPLICATION_TOKEN"
    );
  }
}

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM