Skip to main content

Connecting Your Application to InterSystems IRIS Cloud Document

This document explains how to make programmatic connections to InterSystems IRIS® Cloud Document from applications written in Java or .NET. Such connections encompass multiple options and can be coded in different ways; this document provides illustrative examples that can be quickly examined and understood. As part of the instructions for basic connection code, you must protect connections with TLS encryption, using a self-signed certificate provided by the target; this document details some ways in which you might do so. Each of the sections listed below contains a link to more comprehensive documentation.

Connect from Java
Connect from .NET

Connecting your Java or .NET application to Cloud Document involves just three simple steps:

  1. Download the InterSystems document driverOpens in a new tab for Java or .NET and their dependency, a supported version of JDBC (minimum 3.10.1) or ADO.NET (minimum 2.3.3).

  2. Gather the connection informationOpens in a new tab for the Cloud Document deployment you want to connect to, which includes the hostname and superserver port of the target deployment, credentials to authenticate to the deployment, and the namespace to connect to. You can find the connection information on your deployment’s Deployment Details page in the InterSystems Cloud Services Portal.

  3. Add the needed code to your application, as explained in the following sections. You can copy the completed connection code from the listing at the end of each section.

For detailed online learning content about the use of some of these languages with InterSystems products, see Connecting to InterSystems Products with External LanguagesOpens in a new tab. For information about all of the connections tools available from InterSystems, see Connection ToolsOpens in a new tab.

Important:

One of the required parameters in the connection code shown in this document is namespace (with the value USER throughout). Cloud Document makes the distinction between the physical databases that store data and the logical namespaces used to interact with them, and the relationships between namespaces and databases may differ from one Cloud Document instance to the next. To interact with any given data, therefore, you must determine and specify the appropriate namespace.

Third-party tools and technologies you might use to connect to InterSystems products or services likewise interact with namespaces only, but most use the standard term database to refer to them.

Connect from Java

Before using these instructions, you should make sure that:

  • Your development system has version 1.8 of the JDK and the Java IDEOpens in a new tab of your choice installed and has network access to your Cloud Document deployment.

  • You have downloadedOpens in a new tab the InterSystems JDBC driver, intersystems-document-version.jar, to your development system.

  • You have gathered the connection informationOpens in a new tab for the Cloud Document deployment you want to connect to. In particular, you have identified the hostname, port, namespace, username, and password for your deployment found in the Making External Connections table on the Deployment Overview page in the InterSystems Cloud Services Portal.

  • You have obtained or downloaded the self-signed X.509 certificate provided by the Cloud Document deployment (found on the Deployment Overview page in the InterSystems Cloud Services Portal) and have placed it in a secure location.

You can copy the completed connection code from the listing that follows the instructions, including the steps required to add TLS encryption to the connection.

To code a JDBC connection to Cloud Document, follow these steps:

  1. Add the InterSystems Cloud Document driver, intersystems-document-version.jar, as a dependency to your project.

  2. On the operating system command line, issue the following command to add the X.509 certificate to your keystore, supplying a keystore password and confirming Trust this certificate? [no]: yes as requested:

    keytool -importcert -file path-to-cert/cert-file.pem -keystore keystore.jks
    

    Then, in the directory containing the Java file in which you are coding the connection, create a configuration file named SSLConfig.properties and includes these properties:

    trustStore=path-to-keystore/keystore.jks
    trustStorePassword=keystore-password
    
  3. Create a main method and import the com.intersystems.document.* libraries. Then, create a DataSource object and set its fields to the appropriate connection values as indicated in the example. Be sure to also set the connection security level to 10.

    After setting the parameters for the server connection, call preStart() to initialize a pool size, then call getConnection() to create the connections. Be sure to close the connection with close() when you are finished with it.

    You can copy the following template code below:

    import com.intersystems.document.*;
    
    public class JDBCConnection {
        public static void main (String[] args) throws Exception {
            DataSource pool = DataSource.createDataSource();
            pool.setServerName("???");   // replace ??? with the hostname of your deployment
            pool.setPortNumber(???);     // replace ??? with the port number of your deployment
            pool.setDatabaseName("???"); // replace ??? with the namespace specified by your deployment
            pool.setUser("SQLAdmin");
            pool.setPassword("------");  // enter the password you created for the deployment
            pool.setConnectionSecurityLevel(10);
            
            pool.preStart(10);
            pool.getConnection();
            System.out.println("Connection created");
            
            // use the connection here
            
            pool.close()
        }
    }
    

For more information about using the Cloud Document driver, see Using Document Database with JavaOpens in a new tab.

For detailed information about connecting with TLS from Java applications, see Configuring Java Clients to Use TLS with InterSystems IRISOpens in a new tab.

Connect from .NET

Before using these instructions, you should make sure that:

  • Your development system has the .NET framework and Visual Studio (or another .NET IDEOpens in a new tab of your choice) installed, and has network access to your Cloud Document deployment.

  • You have downloadedOpens in a new tab the Cloud Document NuGet package, InterSystems.Data.Document.version.nupkg, to your development system.

  • You have gathered the connection informationOpens in a new tab for the Cloud Document deployment you want to connect to. In particular, you have identified the hostname, port, namespace, username, and password for your deployment found in the Making External Connections table on the Deployment Overview page in the InterSystems Cloud Service Portal.

  • You have obtained or downloaded the self-signed X.509 certificate provided by the Cloud Document deployment (found on the Deployment Overview page in the InterSystems Cloud Services Portal) and have placed it in a secure location.

You can copy the completed connection code from the listing that follows the instructions, including the steps required to add TLS encryption to the connection.

To code a .NET connection to Cloud Document, follow these steps:

  1. Add the Cloud Document NuGet package, InterSystems.Data.Document.version.nupkg, as a dependency to your project.

  2. Install the X.509 certificate using the instructions for your platform, below. (Both Windows and UNIX/Linux systems provide several ways to install certificates.)

    • On Windows, open a Command Prompt window and enter the following command to add the certificate to the Trusted Root Certification Authorities\ store under Current User:

      certutil -user -addstore Root path-to-certificate\certificate-file.pem 
      
    • On the UNIX or Linux command line, follow these steps:

      1. Enter the following command to install the Dotnet Certificate Tool, dotnet-certificate-tool (see https://github.com/gsoft-inc/dotnet-certificate-toolOpens in a new tab):

        dotnet tool install --global dotnet-certificate-tool
        
      2. Use the tool to add the certificate to the Root store under CurrentUser (be sure to include --store-name Root as shown):

        certificate-tool add --cert path-to-certificate\certificate-file.pem --store-name Root
        
        Note:

        If the certificate is not in PEM format, use the appropriate flag in place of --cert; if the certificate is password-protected, include the --password flag. For more information, see the README file on GitHub.

  3. Import the driver by specifying using InterSystems.Document; at the top of your file. Then, create a DataSource object and set its fields to the appropriate connection values as indicated in the example below. Finally, call GetConnection() to create the connection. Be sure to close the connection with Close() when you are finished with it.

    You can copy the following template code below:

    using InterSystems.Document;
    
    DataSource ds = DataSource.CreateDataSource();
    
    string server = "???";    // replace ??? with the hostname of your deployment
    string port = "???";      // replace ??? with the port number of your deployment
    string ns = "???";        // replace ??? with the namespace specified by your deployment
    string user = "SQLAdmin";
    string pwd = "----";      // enter the password you created for the deployment
    string connectionString = $"Server={server}; Port={port}; Namespace={ns}; User ID={user}; Password={pwd}; SSL = true";
    
    try
    {
        ds.SetConnectionString(connectionString);
        Connection connection = ds.GetConnection();
        
        // use the connection here
        Console.WriteLine("Made connection");
        
        ds.Close();
    } catch (Exception e)
    {
        Console.WriteLine(e.Message);
    }
    

For more information about using .NET with Cloud Document, see Using Document Database with .NETOpens in a new tab.

For more detailed information about connecting with TLS from .NET applications, see Configuring .NET clients to Use TLS with InterSystems IRISOpens in a new tab.

FeedbackOpens in a new tab