Hello,
I have just configured ODBC access on Ubuntu 20.04 to DB2 for Linux 11.5.
The DB2 server (including ODBC/CLI client) is installed on the same machine as Dyalog APL.
Here is what I did:
1. Install and configure unixODBC driver manager
1.1 Install the packages unixodbc and unixodbc-dev
For example, in a terminal window execute the following command:
Code: Select all
sudo apt-get install unixodbc unixodbc-dev
1.2 Locate the configuration file odbcinst.ini
Execute the following command
It will return something like:
Code: Select all
unixODBC 2.3.7
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/yae/.odbc.ini
SQLULEN Size.......: 8
SQLLEN Size........: 8
SQLSETPOSIROW Size.: 8
The full path of the configuration file is shown at the line DRIVERS............:
1.3 Configure unixODBC for your instance of DB2
Edit the file referenced by the line DRIVERS............: above
(i.e. /etc/odbcinst.ini) to add the following stanza:
Code: Select all
[Db2]
Description = Db2 Driver
Driver = <instance_path>/lib/libdb2o.so
fileusage=1
dontdlclose=1
<instance_path> is the instance owner's home directory, for example /home/db2inst1
The command invoking the editor should be prefixed by sudo:
Code: Select all
sudo gedit /etc/odbcinst.ini
sudo nano /etc/odbcinst.ini
sudo vi /etc/odbcinst.ini
2. Configure your ODBC user data source.
Edit the file .odbc.ini in your home directory (no sudo this time!).
Let's assume you want to access the database SAMPLE in the instance db2inst1.
2.1. Add the following line into the stanza [ODBC Data Sources]
2.3 Add the following new stanza
Code: Select all
[SAMPLE]
Driver = /home/db2inst1/sqllib/lib/libdb2o.so
Description = Sample Db2 ODBC Database
3. Test the configuration
3.1. Start Dyalog APL
3.2 Execute the following
)load sqapl
/opt/mdyalog/18.0/64/unicode/ws/sqapl.dws saved Thu Jul 16 02:13:00 2020
SQA.Init ''
0 SQAPL loaded from: cxdya63u64v.so Using default translation no aplunicd.ini
present
SQA.DSN ''
0 myodbc53u /usr/local/lib/libmyodbc5w.so
SAMPLE /home/db2inst1/sqllib/lib/libdb2.so
SQA.Connect 'c1' 'SAMPLE'
0
3⊃SQA.Do 'c1' 'select * from DB2INST1.STAFF fetch first 3 rows only'
10 Sanders 20 Mgr 7 98357.5 0
20 Pernal 20 Sales 8 78171.25 612.45
30 Marenghi 38 Mgr 5 77506.75 0
SQA.Close '.'
0
)off
4. Enjoy!
--
Yves-Antoine Emmanuelli.