DB2: Getting [IBM][CLI Driver] SQLSTATE=58004 SQLCODE=-1042

Question:

I am new to IBM DB2 world and trying to establish a connection with DB2 using Jupyter notebook:

import ibm_db

try:
    ibm_db.pconnect("DATABASE=DB2;HOSTNAME=hostname;PORT=60000;PROTOCOL=TCPIP;UID=user;PWD=password;", "", "")
    print("Connected to DB")
except Exception as e:
    print(e)

But getting:

[IBM][CLI Driver] SQL1042C  An unexpected system error occurred.  SQLSTATE=58004 SQLCODE=-1042

Any suggestions here?

Edit:

Got the solution for the issue. Posting it here so someone might be helped:

Add AUTHENTICATION=SERVER in the ibm_db.pconnect string.

Asked By: Alpha001

||

Answers:

Add AUTHENTICATION=SERVER in the ibm_db.pconnect string.

Answered By: SovietFrontier

If you’re code works on Linux but fails on Windows, this might also help:

You may be experiencing a known defect that affects some Microsoft Windows configurations.

Use pip show ibm_db to find the "Location:" of your site-packages
directory.

Suppose for example, that directory is c:pythonlibsite-packages

Your installation directory will be different, but try to understand
the idea.

Then modify your PATH environment variable to append the following
directory to the PATH:

c:pythonlibsite-packagesclidriverbinamd64.VC12.CRT

(that is, your site-packages path with clidriverbinamd64.VC12.CRT
appended to it )

After modifying the PATH, you can retry the python ibm_db database
connection.

If you do not have permission to modify the PATH, you can also copy
the contents (2 .DLL files) of that amd64.VC12.CRT directory , into
another directory that you know will be already on the PATH when
python runs.

If you are encrypting your database connections with SSL/TLS, you
sometimes also need to add a second directory to the PATH ( …
site-packagesclidriverbinicc64 ) .

From https://github.com/ibmdb/python-ibmdb/issues/599

Answered By: Matthias
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.