Search code examples
matlabcassandradatastax-astra

How do I connect MATLAB to Astra DB?


I have developed a database on Astra db, a DaaS application. I ran into some issues trying to connect it to MATLAB and would like some possible explanations and maybe solutions as to why this happened.

I tried using a secure bundle and an ODCB driver. However, I was not able to connect to the database on either approach.

If any further information is needed, comment and I will update this post.


Solution

  • Give the following articles a read if you haven't already...

    Give the following a try...

    Step-1: From the Astra console, generate an application token - see Manage application tokens for guidance. To make things simple, the token's role to "Administrator User". Save the client id, client secret, and token. You'll need them later.

    Step-2: From the Astra console, download the secure-connection-bundle for your database. From the main dashboard, click on your database, choose the Connect tab, and click the Download Bundle button.

    Step-3: Unzip the secure connection bundle and open the config.json file. Pull the host and port from the file.

    Step-4: In Matlab, script your connection and query out. You'll need the Database Toolbox if you're trying this from Matlab online.

    datasource = "CassandraDataSource";
    username = "<client_id>";
    password = "<client_secret>";
    conn = apacheCassandra(datasource, username, password, 'ContactPoints', <host>, 'PortNumber', <port>, 'SSLEnabled', true);
    
    query = strcat("SELECT whatevs ", ... 
        "FROM keyspace.table ", ...
        "WHERE primary_key IN ('foo','bar')";
    
    results = executecql(conn, query);
    
    close(conn)
    

    Good luck!