|
| 1 | +# Cloud |
| 2 | + |
| 3 | +## Connecting to your [DataStax Apollo database on Constellation] using a secure connection bundle |
| 4 | + |
| 5 | + **Note:** Both the C++ Driver for Apache Cassandra and the C++ Driver for DataStax |
| 6 | + Enterprise (DSE) use the same code to connect and query your Cassandra database, |
| 7 | + but when using the DSE driver use the header `#include <dse.h>`. |
| 8 | + |
| 9 | + Use the following code snippet to connect your database: |
| 10 | + |
| 11 | + ```c |
| 12 | + #include <cassandra.h> /* Use "#include <dse.h>" when using the C++ DSE Driver */ |
| 13 | + #include <stdio.h> |
| 14 | + |
| 15 | + int main(int argc, char* argv[]) { |
| 16 | + /* Setup and connect to cluster */ |
| 17 | + CassCluster* cluster = cass_cluster_new(); |
| 18 | + CassSession* session = cass_session_new(); |
| 19 | + |
| 20 | + /* Setup driver to connect to the cloud using the secure connection bundle */ |
| 21 | + const char* secure_connect_bundle = "/path/to/secure-connect-database_name.zip"; |
| 22 | + if (cass_cluster_set_cloud_secure_connection_bundle(cluster, secure_connect_bundle) != CASS_OK) { |
| 23 | + fprintf(stderr, "Unable to configure cloud using the secure connection bundle: %s\n", |
| 24 | + secure_connect_bundle); |
| 25 | + return 1; |
| 26 | + } |
| 27 | + |
| 28 | + /* Set credentials provided when creating your database */ |
| 29 | + cass_cluster_set_credentials(cluster, "username", "password"); |
| 30 | + |
| 31 | + CassFuture* connect_future = cass_session_connect(session, cluster); |
| 32 | + |
| 33 | + if (cass_future_error_code(connect_future) == CASS_OK) { |
| 34 | + /* Use the session to run queries */ |
| 35 | + } else { |
| 36 | + /* Handle error */ |
| 37 | + } |
| 38 | + |
| 39 | + cass_future_free(connect_future); |
| 40 | + cass_cluster_free(cluster); |
| 41 | + cass_session_free(session); |
| 42 | + |
| 43 | + return 0; |
| 44 | + } |
| 45 | + ``` |
| 46 | +
|
| 47 | + **Note:** `cass_cluster_set_contact_points()` and `cass_cluster_set_ssl()` should not used |
| 48 | + in conjunction with `cass_cluster_set_cloud_secure_connection_bundle()`. |
| 49 | +
|
| 50 | +[DataStax Apollo database on Constellation]: https://constellation.datastax.com/ |
0 commit comments