Support for ODBC was added in Profound.js 5.3.0.
Profound.js's "odbc" database driver enables database connectivity via the Open Database Connectivity (ODBC) standard. The "odbc" driver can be used to connect to any database supported by Profound.js, but is primarily designed and tested for connecting to DB2 on IBM i. For the other supported databases, the DB-specific drivers should be used instead.
The "odbc" driver offers a few advantages over Profound.js's "IBMi" driver:
- Increased performance, both for connections to a remote IBM i and for connections from IBM i to the local database.
- Connections to multiple IBM i systems are supported. The "IBMi" driver only supports connecting to a single IBM i system.
- Nothing needs to be installed on target IBM i systems. The "IBMi" driver requires a Profound.js installation on the target IBM i system.
The "odbc" driver can be used to run SQL statements against DB2 for i using the following APIs:
- Low Code database plugins
- pjs.query()
- Data API
- Record Level Access via SQL
- Other SQL APIs
The "odbc" driver does not allow non-SQL APIs (such as for program/procedure call, CL command, etc.) to run against the target system.
Installation
The "odbc" driver utilizes 3 different components that need to be installed on the 'source' system only. Meaning, the system where you are running Profound.js and want to connect to IBM i.
- The Profound.js "odbc" driver. This component is built into Profound.js, starting with version 5.3.0 and relies on the following components for connectivity to the target system.
- The open source package odbc, which must be installed separately via NPM. This package provides a Node.js interface for using ODBC drivers.
- The ODBC driver for the target system. This package performs the actual work of communicating with the target database. For example, ODBC access to IBM i is provided by the IBM i Access ODBC Driver, which is supplied by IBM.
Installing the odbc Package with NPM
See the package's installation instructions on NPM, here:
https://www.npmjs.com/package/odbc
Follow the instructions for installing necessary pre-requisites, depending on your operating system. When installing the package itself it's recommended to install the latest beta version, due to performance issues in the current release. To do that, run this command from your Profound.js installation directory instead of using the command suggested on the NPM page:
npm install odbc@beta
Installing the IBM i Access ODBC Driver
The ODBC driver is provided as part of the IBM i Access Client Solutions Application Package. The Application Package is a separate installation from the main ACS installation that includes the TN5250 emulator. Versions are available for Windows, Linux, Mac, and IBM i. To download the Application Package, visit the IBM i ACS Home Page here:
https://www.ibm.com/support/pages/ibm-i-access-client-solutions
An IBM account is required to access the downloads. Click on Downloads for IBM i Access Client Solutions, accept the license agreement, and use the ACS App Pkg link for the appropriate source operating system. For IBM i, use ACS PASE App Pkg. Installation instructions are included in each download package.
The IBM i version of the Application package installs via the open-source package manager "yum". See here for instructions on setting up yum on IBM i:
https://www.ibm.com/support/pages/node/706903
For Application Package installers for 32-bit Windows or languages other than English, visit the IBM ESS Website.
Configuration
Connections are configured using the databaseConnections property in the Profound.js configuration file. For example:
"databaseConnections": [ { "name": "myIBMi", "driver": "odbc", "type": "db2i", "credentialsFile": `${__dirname}/credentials`, "driverOptions": { "connectionString": "system=myIBMi;nam=1;cmt=0;unicodesql=1;tsft=1;dbq=,MYLIB,MYLIB2,MYLIB3", "initialSize": 10, "maxSize": 10, "shrink": false } } ]
The database connections entry has the following properties:
- name (required): A name for the connection. The name can be whatever you choose, but must be unique.
- driver (required): Set to "odbc".
- type (required): The target database type. Can be any of "db2i", "mysql", "mssql", or "oracledb". However, this driver is primarily intended for use with DB2 for IBM i. For other databases, it's recommended to use the DB-specific drivers.
- credentialsFile: (optional): Path to a file containing an encrypted user id / password created by the "store_credentials" utility provided with Profound.js. This is an alternative to specifying the user and password in clear text on the connection string.
- driverOptions: (required): An object containing options for the odbc package's Pool constructor. See the NPM page for supported options. Profound.js's "odbc" driver only supports pooled connections. A pool is created for each databaseConnections entry.
ODBC driver options (such as what system to connect to, etc.) are configured using the "connectionString" property of the "driverOptions" object. Option names/values are separated by an equal sign (=) and each name/value pair is separated by a semi-colon (;). Option names are not case-sensitive. See here for options supported by the IBM i Access ODBC driver:
https://www.ibm.com/docs/en/i/7.4?topic=details-connection-string-keywords
For example, in the above configuration the library list is set to "MYLIB MYLIB2 MYLIB3" with no default schema, using the "dbq" connecting string option, and commitment control is disabled via the "cmt" option. The following settings are required by Profound.js and should be set on all connections:
Option | Required Value |
---|---|
nam | 1 |
unicodesql | 1 |
tsft | 1 |
If connecting to IBM i from outside the private network, it's recommended to set the option "SSL" to 1, to enable encrypted communications.
Creating a Credentials File
The example configuration above uses an encrypted credentials file. To create a credentials file, run the following command from your Profound.js installation directory and enter the desired user id and password when prompted:
node store_credentials.js
The credentials file is decrypted when the Profound.js server starts, and the user id and password are appended to the end of the "connectionString" like this:
;uid={decrypted_userid};pwd={decrypted_password};
When using this option, specify the "connectionString" without the "uid" and "pwd" options.
Using ODBC Data Sources (optional)
An ODBC Data Source is an alternative way of specifying ODBC connection options. A Data Source is an OS-dependent location (such as a file) where ODBC connection options are stored. When using a Data Source, you can simply specify the Data Source Name (DSN) in the "connectionString", and the options are loaded from the Data Source. Connection options can also be specified on the "connectionString" along with the DSN. In this case, the options override those from the Data Source.
The process of creating a Data Source depends on the source operating system.
Creating a Data Source on Linux, Mac, and IBM i
On these systems, Data Sources are stored in a text file named "odbc.ini". The file location depends on the OS, but is typically /etc/odbc.ini. On IBM i, the location is /QOpenSys/odbc.ini. The file can be edited directly, but it's recommended to use the odbcinst command-line utility to add/remove data sources. On IBM i, the odbcinst command can be run in a PASE shell.
To add a data source, create a file named "template.ini" anywhere on the file system and copy/paste the following lines into the file:
[myIBMi] Driver=IBM i Access ODBC Driver System=localhost Naming=1 CommitMode=0 UnicodeSQL=1 TimestampFormat=1
Make the following adjustments to the file:
- The text 'myIBMi' inside the square brackets specifies the Data Source Name. Adding the Data Source will replace an existing Data Source of the same name. Change the 'myIBMi' text to the desired name, leaving the square brackets in place. To check existing DSNs, you can use this command:
odbcinst -q -s
- If connecting from off system to IBM i, change the value of the 'System' property to the host name or IP address of the target IBM i system. Otherwise, leave as localhost.
Other options can be added to the file as desired. When the "template.ini" file is ready, use this command to add the Data Source:
odbcinst -i -s -l -f template.ini
If the command completes successfully, the DSN is added to the "odbc.ini" file. This command can be used to confirm:
odbcinst -q -s -n DATA_SOURCE_NAME
The Data Source configuration should be output to the screen. At this point, the "template.ini" file is no longer necessary and can be removed.
The Data Source Name can now be referenced in the "connectionString" like this:
"databaseConnections": [ { "name": "myIBMi", "driver": "odbc", "type": "db2i", "credentialsFile": `${__dirname}/credentials`, "driverOptions": { "connectionString": "DSN=DATA_SOURCE_NAME;dbq=,DATALIB1,DATALIB2", } } ]
A data source can be removed with this command:
odbcinst -u -s -l -n DATA_SOURCE_NAME
Creating a Data Source on Windows
On Windows, ODBC Data Sources are stored in files in a directory of your choosing. To find the directory currently configured as the location for Data Source files on your system, launch the ODBC Data Sources application by typing 'odbc data sources' into the Windows search box, and choosing the correct version for your Windows installation (usually 64-bit):
The directory for Data Source files is shown on the File DSN tab. This tab also has an option to change the directory, if desired;
To install a Data Source, create a text file with .dsn extension in the appropriate directory. The file name will be the DSN name. Copy/paste these contents into the file:
[ODBC] Driver=IBM i Access ODBC Driver System=myIBMi Naming=1 CommitMode=0 UnicodeSQL=1 TimestampFormat=1
Make the following adjustments to the file:
- Change the value of the 'System' property to the target IBM i system's host name or IP address.
- If connecting to IBM i from outside the private network, it's recommended to add this line to the end of the file to enable encrypted communications:
SSL=1
Additional connection options can be added as desired.
The Data Source Name can now be referenced in the "connectionString" like this:
"databaseConnections": [ { "name": "myIBMi", "driver": "odbc", "type": "db2i", "credentialsFile": `${__dirname}/credentials`, "driverOptions": { "connectionString": "FILEDSN=DATA_SOURCE_NAME;dbq=,DATALIB1,DATALIB2", } } ]
Specify the file name as the value of the FILEDSN option, without the .dsn extension.
To remove or change a DSN, simply edit or delete the file.