Connecting programmatically with ODBC or CLI

Define a connection between a Microsoft Windows ODBC/CLI application and the Db2 database, BLUDB.

Before you begin

Before you can connect to your database, you must carry out the following steps:
  • Verify prerequisites, including installing driver packages, configuring your local environment, and downloading SSL certificates (if needed)

  • Collect connect information, including database details such as host name and port numbers, and connect credentials such as user ID and password

Procedure

  1. Use the version of CLPPlus that is in the Db2 Warehouse image container or client container. Although you must deploy the containers, no setup is required for CLPPlus afterward. For information about how to obtain CLPPlus from the Db2 Warehouse client container, see IBM Db2 Warehouse client container.
  2. Optional: To test the connection to the database, run this command from the command prompt:
    db2cli validate -dsn alias -connect -user userid -passwd password
    where:
    • alias is the alias you created with the db2cli writecfg command
    • userid is from the connect credentials you collected beforehand
    • password is from the connect credentials you collected beforehand
  3. Optional: To register the data source name (DSN) with Microsoft ODBC Driver Manger and to work with Microsoft ODBC applications, run the following command.
    By default, the DSN is created as user DSN.
    db2cli registerdsn -add -dsn  alias
    where
    • alias is the alias that you created with the db2cli writecfg command