How do I connect to a DB2 database from Linux?
To connect to a DB2 database you will need to install a DB2 ODBC client from IBM. We believe version 9.1 works well.
(Make sure you select the 64-bit connector to match your 64-bit Altair SLC installation as we no longer support 32-bit.)
You will need to update or create a odbc.ini file to define the driver, host and database you wish to connect to. If your database is called ‘Test’ and your DB2 client is installed in /opt/ibm/db2/V9.1/lib64 then your odbc.ini file should contain something of the form:
[ODBC Data Source]
Test=DB2
[Test]
Driver=/opt/ibm/db2V9.1/lib64/libdb2.so
Hostname=<YOUR_DB2_MACHINE>
Database=Test
And your odbcinst.ini file should contain something of the form:
[ODBC Drivers]
DB2=Installed
[DB2]
Description=DB2 Odbc Driver
Driver=/opt/ibm/db2/V9.1/lib64/libdb2.so
Environmental variables ODBCINI and ODBCINST should point to the above files.
You then need to update your LD_LIBRARY_PATH environmental variable to contain the path to the DB2 client library wherever that is installed. In this case that would be /opt/ibm/db2/V9.1/lib64.
After that you should be able to run Altair SLC and connect to your DB2 database using a LIBNAME statement of the form:
libname dblib DB2 user=UUUUUU password=XXXXXXXX databaseName=Test dsn=Test;
or using explicit passthrough such as
proc sql;
connect to DB2 as db2conn (user=UUUUUUU password=XXXXXXX dsn=Test);
create table localtest as
select * from connection to db2conn (select * from YOURTABLE);
disconnect from db2conn;
quit;