Testing connectivity to a database

You can create a Transport Layer Security (TLS) or non-TLS connection between IBM Data Server Client or IBM Data Server Runtime Client and a database by using the Db2 CLI or CLP.

Before you begin

Obtain and apply the IBM Data Server Client or IBM Data Server Runtime Client Version 11.5 package that applies to your client machine’s operating system. Refer to the link to download and install it: IBM Data Server Client or IBM Data Server Runtime Client.

Before you can connect to your database, you must perform two steps:

  • Verify prerequisites, including installing driver packages, configuring your local environment, and if needed downloading TLS certificates.
  • Collect connect information, including database details such as host name and port numbers, and connect credentials such as user ID and password.

If you intend to connect by using the TLS protocol, download the appropriate TLS certificate (for example, SampleSSLCert.crt) to a directory on the client machine.

About this task

Complete the set of steps that applies to the type of connection that you want to create.

Procedure

Use one of the following approaches:

  • To create a connection without using TLS, complete the following steps:
    1. Catalog the Server node so that client applications can connect to it.
      Issue the following command:
      db2 catalog tcpip node node_name remote dashDB_IP_address server port
      Where:
      • node_name represents your name for the node.
      • dashDB_IP_address represents the IP address of the server.
      • port is the port that is used to connect to Server without using an TLS connection. If you are using the default port, specify 50000.
    2. Catalog the remote Server database so that client applications can connect to it.
      Issue the following command:
      db2 catalog database SAMPLEDB as db_alias at node node_name
      Where db_alias represents your name for the Server database.
    3. Test the non-TLS connection that uses CLP by issuing the following command to connect to the database:
      db2 connect to db_alias user user_id
      Where user_id represents your Db2® Warehouse user ID. You are prompted to enter your password.

      Or

      Test the TLS connection that uses CLI by issuing the following command to connect to the database:
      db2cli validate -dsn alias -connect -user userid -passwd password
      Where:
      • alias is an alias that you created with the db2cli writecfgcommand.
      • userid is your Db2 user ID.
      • password is your Db2 password.
  • To create a connection by using TLS, complete the following steps:
    1. Refer to Configuring TLS Support in a non-Java Db2 client using a certificate file for instructions on how to set up TLS using the SamplSSLCert.crt file that was downloaded.
    2. Test the SSL connection that uses CLI by issuing the following command to connect to the database:
      db2cli validate -dsn alias -connect -user userid -passwd password 
      Where:
      • alias is an alias that you created with the db2cli writecfg command.
      • userid is your Db2 user ID.
      • password is your Db2 password.
    3. If you are using Db2 11.5.7 or later, embedded SQL applications including the CLP can use a certificate file to configure a TLS connection. The TLS connection details must be specified in the db2dsdriver.cfg. To test the connection, issue the following command:
      db2 connect to db_alias user user_id

      Where user_id represents your Db2 Warehouse user ID. You are prompted to enter your password.