• Glossary
  • Support
  • Downloads
  • DataStax Home
Get Live Help
Expand All
Collapse All

DataStax Astra DB Classic Documentation

    • Overview
      • Release notes
      • Astra DB FAQs
      • Astra DB glossary
      • Get support
    • Getting Started
      • Grant a user access
      • Load and retrieve data
        • Use DSBulk to load data
        • Use Data Loader in Astra Portal
      • Connect a driver
      • Build sample apps
      • Use integrations
        • Connect with DataGrip
        • Connect with DBSchema
        • Connect with JanusGraph
        • Connect with Strapi
    • Planning
      • Plan options
      • Database regions
    • Securing
      • Security highlights
      • Security guidelines
      • Default user permissions
      • Change your password
      • Reset your password
      • Authentication and Authorization
      • Astra DB Plugin for HashiCorp Vault
    • Connecting
      • Connecting to a VPC
      • Connecting Change Data Capture (CDC)
      • Connecting CQL console
      • Connect the Spark Cassandra Connector to Astra
      • Drivers for Astra DB
        • Connecting C++ driver
        • Connecting C# driver
        • Connecting Java driver
        • Connecting Node.js driver
        • Connecting Python driver
        • Drivers retry policies
      • Connecting Legacy drivers
      • Get Secure Connect Bundle
    • Migrating
      • FAQs
      • Preliminary steps
        • Feasibility checks
        • Deployment and infrastructure considerations
        • Create target environment for migration
        • Understand rollback options
      • Phase 1: Deploy ZDM Proxy and connect client applications
        • Set up the ZDM Automation with ZDM Utility
        • Deploy the ZDM Proxy and monitoring
          • Configure Transport Layer Security
        • Connect client applications to ZDM Proxy
        • Manage your ZDM Proxy instances
      • Phase 2: Migrate and validate data
      • Phase 3: Enable asynchronous dual reads
      • Phase 4: Change read routing to Target
      • Phase 5: Connect client applications directly to Target
      • Troubleshooting
        • Troubleshooting tips
        • Troubleshooting scenarios
      • Additional resources
        • Glossary
        • Contribution guidelines
        • Release Notes
    • Managing
      • Managing your organization
        • User permissions
        • Pricing and billing
        • Audit Logs
        • Configuring SSO
          • Configure SSO for Microsoft Azure AD
          • Configure SSO for Okta
          • Configure SSO for OneLogin
      • Managing your database
        • Create your database
        • View your databases
        • Database statuses
        • Use DSBulk to load data
        • Use Data Loader in Astra Portal
        • Monitor your databases
        • Manage multiple keyspaces
        • Using multiple regions
        • Terminate your database
        • Resize your classic database
        • Park your classic database
        • Unpark your classic database
      • Managing with DevOps API
        • Managing database lifecycle
        • Managing roles
        • Managing users
        • Managing tokens
        • Managing multiple regions
        • Get private endpoints
        • AWS PrivateLink
        • Azure PrivateLink
        • GCP Private Service
    • Astra CLI
    • Developing with Stargate APIs
      • Develop with REST
      • Develop with Document
      • Develop with GraphQL
        • Develop with GraphQL (CQL-first)
        • Develop with GraphQL (Schema-first)
      • Develop with gRPC
        • gRPC Rust client
        • gRPC Go client
        • gRPC Node.js client
        • gRPC Java client
      • Develop with CQL
      • Tooling Resources
      • Node.js Document API client
      • Node.js REST API client
    • Stargate QuickStarts
      • Document API QuickStart
      • REST API QuickStart
      • GraphQL API CQL-first QuickStart
    • API References
      • DevOps REST API v2
      • Stargate Document API v2
      • Stargate REST API v2
  • DataStax Astra DB Classic Documentation
  • Connecting
  • Drivers for Astra DB
  • Connecting C++ driver

DataStax C++ driver

Before using the DataStax driver, review the Best practices for DataStax drivers to understand the rules and recommendations for improving performance and minimizing resource utilization in applications that use a DataStax driver.

DataStax recommends using the unified DataStax driver. See this blog post for more information. You can also use the DataStax Enterprise (DSE) drivers, which exposes the same API for connecting to Cassandra databases.

Prerequisites

  • Create your database and set your environment variables to save time developing on your database. There are four environment variables, three of which are on the Astra dashboard (database id, region, and keyspace), and one that you must create (token). For more, see Create your database.

  • DataStax C++ driver download links

    Download the DataStax C++ driver and dependency packages for your platform using the links in the following table:

Platform Driver Dependencies

CentOS 6

Download

Download

CentOS 7

Download

Download

Ubuntu 14.04

Download

Download

Ubuntu 16.04

Download

Download

Ubuntu 18.04

Download

Download

Windows

Download

Download

  • Other platforms should build the driver from the source code packages.

  • Using the packages you downloaded, follow the installation instructions for your platform to install the DataStax C++ driver.

  • Client ID and Client Secret by creating your application token for your username and password.

Working with secure connect bundle

Downloading secure connect bundle

To connect to your Astra DB database using the drivers, download the secure database bundle from the DataStax Astra Portal that contains the connection credentials.

  1. Open a browser, navigate to Astra DB, and log in.

  1. From your Dashboard page, select your database.

  1. On the Overview page, select Connect.

  1. In the Select a Method section, select Drivers and then Legacy from the dropdown menu to select your driver type from the list to load language-specific instructions.

    Java and Node.js are available as legacy and cloud native drivers.

    If you have multiple regions, select the region you want to connect to from the dropdown menu for instructions.

    The bundle URL is the same for all languages.

  1. Click Download Bundle.

    If you have multiple regions, you will have the option to download a bundle for each region from the expanded Download Bundle drop-down menu.

If you’ve enabled VPC peering, you can also Download External Secure Connect Bundle for use within your VPC peering.

The secure-connect-database_name.zip file downloads, which contains the security certificates and credentials for your database.

VPC peering is only available on Classic databases.

Sharing secure connect bundle

Although teammates can access your Astra DB database, it will not display in their list of available databases under My Databases in Astra Portal.

After you create an Astra DB database, you can grant access to other members of your team by providing them with the database credentials and connection details for your database.

Be careful when sharing connection details. Providing this information to another user grants them access to your Astra DB database and ownership capabilities, such as making modifications to the database.

For security, delete downloaded connection credentials after sending them to your teammate.

Connecting C++ driver

  1. Create a connect_database.c file in the main directory for your C++ project.

cd my_project
touch connect_database.c
  1. Copy the following connection code into the connect_database.c file. The secure_connect_bundle must include the absolute path to your Astra database credentials (secure-connect-database_name.zip).

The cass_cluster_set_contact_points() and cass_cluster_set_ssl() methods should not used in conjunction with the cass_cluster_set_cloud_secure_connection_bundle() method.

#include <cassandra.h>
#include <stdio.h>

int main(int argc, char* argv[]) {
     /* Setup and connect to cluster */
     CassCluster* cluster = cass_cluster_new();
     CassSession* session = cass_session_new();

     /* Setup driver to connect to the cloud using the secure connection bundle */
     const char* secure_connect_bundle = "/path/to/secure-connect-database_name.zip";
     if (cass_cluster_set_cloud_secure_connection_bundle(cluster, secure_connect_bundle) != CASS_OK) {
       fprintf(stderr, "Unable to configure cloud using the secure connection bundle: %s\n",
               secure_connect_bundle);
       return 1;
     }

     /* Set credentials provided when creating your database */
     cass_cluster_set_credentials(cluster, "clientID", "clientSecret");

     CassFuture* connect_future = cass_session_connect(session, cluster);

     if (cass_future_error_code(connect_future) == CASS_OK) {
       /* Use the session to run queries */
     } else {
       /* Handle error */
     }

     cass_future_free(connect_future);
     cass_cluster_free(cluster);
     cass_session_free(session);

     return 0;
   }
  1. Build and link your application against the DataStax C++ driver.

    • Linux or macOS

For static linking, use cassandra_static.a.

cc connect-database.c -I/path/to/cassandra.h -L/path/to/cassandra.so -lcassandra
  • Windows Include these libraries in your Microsoft Visual Studio project by adding them to the project’s properties under Configuration Properties/Linker/Input/Additional Dependencies.

For static linking, use cassandra_static.lib.

Link your application against cassandra.lib. Your application will also require `cassandra.dll to be in your runtime path.

  1. After connecting to your database, use the following code to query your database. This code creates a CassStatement object to connect to your Astra DB database, runs a CQL query, and prints the output to the console.

/* Build statement and execute query */
const char_ query = "SELECT release_version FROM system.local";
CassStatement* statement = cass_statement_new(query, 0);

CassFuture* result_future = cass_session_execute(session, statement);

if (cass_future_error_code(result_future) == CASS_OK) {
  /* Retrieve result set and get the first row _/
  const CassResult_ result = cass_future_get_result(result_future);
  const CassRow* row = cass_result_first_row(result);

  if (row) {
    const CassValue* value = cass_row_get_column_by_name(row, "release_version");

    const char* release_version;
    size_t release_version_length;
    cass_value_get_string(value, &release_version, &release_version_length);
    printf("release_version: '%._s'\n", (int)release_version_length, release_version);
  }

    cass_result_free(result);
  } else {
    /_ Handle error _/
    const char_ message;
    size_t message_length;
    cass_future_error_message(result_future, &message, &message_length);
    fprintf(stderr, "Unable to run query: '%.*s'\n", (int)message_length, message);
  }

  cass_statement_free(statement);
  cass_future_free(result_future);

Migrating C++ driver

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 DB.

  1. In your existing DataStax C++ driver code, modify the connection code to use the Astra DB API.

    Both the DataStax C driver for Apache Cassandra and the {company} Enterprise (DSE) C driver use the same code to connect and query your Astra database. When using the DSE C++ driver, use the header #include <dse.h>.

    The secure_connect_bundle must include the absolute path to your Astra database credentials (secure-connect-database_name.zip).

    cass_cluster_set_credentials(cluster, "clientId", "clientSecret");
    
      CassFuture* connect_future = cass_session_connect(session, cluster);
      if (cass_future_error_code(connect_future) == CASS_OK) {
        * Use the session to run queries _
        }
      else {
        _ Handle error *
      }
  2. Build and link your application against the DataStax C++ driver.

    • Linux or macOS

      For static linking, use cassandra_static.a or dse_static.a.

      • DataStax C++ driver for Apache Cassandra

      • DSE C++ driver

      cc connect-database.c -I/path/to/cassandra.h -L/path/to/cassandra.so -lcassandra
      cc connect-database.c -I/path/to/dse.h -L/path/to/dse.so -ldse
    • Windows Include these libraries in your Microsoft Visual Studio project by adding them to the project’s properties under ]Configuration Properties/Linker/Input/Additional Dependencies.

      For static linking, use cassandra_static.lib or dse_static.libpass:c[.

DataStax C++ driver for Apache Cassandra Link your application against cassandra.lib. Your application will also require `cassandra.dll to be in your runtime path.

DSE C++ driver Link your application against dse.lib. Your application will also require dse.dll to be in your runtime path.

Drivers for Astra DB Connecting C# driver

General Inquiries: +1 (650) 389-6000 info@datastax.com

© DataStax | Privacy policy | Terms of use

DataStax, Titan, and TitanDB are registered trademarks of DataStax, Inc. and its subsidiaries in the United States and/or other countries.

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.

landing_page landingpage