Skip to content Skip to sidebar Skip to footer

Cannot Connect To Db2 From Python

I installed ibm_db in python with pip install ibm_db and created a db2dsdriver.cfg file with the following content:

Solution 1:

You are using the python build as delivered by miniconda / anaconda, and this may be the determining factor.

A workaround is to use conda to build ibm_db locally and to install the newly built package from local. Other workarounds may be possible.

The instructions for building conda packages and installing them are here and related pages.

For Win10 x64 20H2 with anaconda 2020.11 (4.9.2) the following commands let me use python ibm_db module to connect to Db2, at least from the anaconda prompt.

  • Install Anaconda 2020.11 for Microsoft Windows x64.
  • In a administrator-mode Anaconda3 prompt window run these commands (ensuring each command completes successfully before running the next one):
  • conda install conda-build git anaconda-clean m2-patch
  • conda update conda conda-build git m2-patch
  • cd /d %userprofile%
  • if directory ibm_db exists the rename it or remove it.
  • conda skeleton pypi ibm_db
  • conda-build ibm_db
  • conda install --use-local ibm_db

If you now run conda list, it's output should contain ibm_db module, and the python (3.8.5) will connect to Db2 , at least when used in the anaconda prompt window.

If you continue to get the same SQL1042C symptom, verify that the PATH has no other Db2-products (other than clidriver\bin) on it, and then add two additional directories to the PATH before launching python. These are the fully qualified pathnames to clidriver\bin\icc64 and clidriver\bin\amd64.vc12.crt (or whatever the amd64.vc.XX.crt is present under clidriver\bin). This is not normally needed, there is is a defect in clidriver for some specific configurations that makes it necessary, and IBM should deliver a fix at some future time (IT34327).


Post a Comment for "Cannot Connect To Db2 From Python"