2

I am able to connect to DB2 just fine with my TOAD application however I need to be able to connect within python to build some automated reports.

I have installed the ibm_db library and I am trying to follow the instructions but I keep getting error SQLCODE=-30081.

import ibm_db

conn_str = 'database=XXXX;hostname=XXXX.host.com;port=11111;protocol=tcpip;uid=user;pwd=password'
conn = ibm_db_conn = ibm_db.connect(conn_str,'','')

Traceback:

Traceback (most recent call last):
  File "C:/Users/username/PycharmProjects/Report/MAIN/MAIN.py", line 4, in <module>
    conn = ibm_db_conn = ibm_db.connect(conn_str,'','')
 SQLCODE=-30081

Looking up -30081 is not very helpful as it can be caused by a list of things.

I did read somewhere that maybe ibm_db is only supported on Python 3.4 and I am using Python 3.6 however I cannot install Python 3.4 on my work PC right now as its admin locked.

Update:

Tested connection using the command line with the 2 different connections options available to ibm_db.

Both connections types:

import ibm_db


conn_str = 'database=XXXX;hostname=111.111.111.111;port=11111;protocol=tcpip;uid=username;pwd=password'

try:
    conn = ibm_db.connect(conn_str, '', '')
except:
    print("no connection:", ibm_db.conn_errormsg())
else:
    print("The 1st connection was successful")

try:
    conn = ibm_db.connect('XXXX', 'username', 'password')
except:
    print("no connection:", ibm_db.conn_errormsg())
else:
    print("The 2nd connection was successful")

Error:

C:\Users\username\Desktop\Python 3.6.2>python test.py
no connection: [IBM][CLI Driver] SQL30081N  A communication error has been detected. Communication protocol being used: "TCP/IP".  Communication API being used: "SOCKETS".  Location where the error was detected: "111.111.111.111".  Communica SQLCODE=-30081etecting the error: "recv".  Protocol specific error code(s): "10054", "*", "0".  SQLSTATE=08001
no connection: [IBM][CLI Driver] SQL30082N  Security processing failed with reason "19" ("USERID DISABLED or RESTRICTED" SQLCODE=-30082001

Any guidance would be appreciated.

11
  • Is this the correct port? Any details on the error? Can you telnet to that host and port? Commented Mar 25, 2019 at 15:45
  • @data_henrik The port is invalid for the sake of the post but the port used in the code is correct as I can connect just fine using my other query tools. There are no detailed errors. That traceback is all I get. I am not able to telnet as it is not a function I am allowed to do at work however I can run queries just fine using my other reporting tools like TOAD. Commented Mar 25, 2019 at 15:55
  • Any firewall or Db2 security setting (e.g., trusted context) that filters based on application name or similar? Commented Mar 25, 2019 at 16:05
  • @data_henrik not that I am aware of. I have connected to other databases using python such as Oracle with this same PC so I do not believe they are filtering per application. Also I have used power query in excel to connect to databases as well and other applications. Commented Mar 25, 2019 at 16:11
  • My python 3.7 works fine with ibm_db on Windows7. Edit your question to add the version of ibm_db that you are using. In your exception handler, print the ibm_db.conn_errormsg() to see the full error message. Commented Mar 25, 2019 at 16:23

1 Answer 1

2

Your error message says:


SQL30082N Security processing failed with reason "19" ("USERID DISABLED or RESTRICTED" SQLCODE=-30082001


Here is one of good articles for this message:

Error SQL30082N Reason Code 19 or 24
https://www.ibm.com/support/pages/error-sql30082n-reason-code-19-or-24

Here is snipped, we may need to follow on Windows:

4.) If you are on Windows please make sure that the group the user is apart of is added to: "Access this computer from network". To check this please do the following:

Click on Start->Run from the Windows start menu Type "secpol.msc" Go to Local Policies->User Rights Assignments. Double-click on "Access this computer from network"

For more information on this topic please see the "Related URL" for more information

Hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Unfortunately I am not able to access secpol.msc on my work computer. My issue has already been resolved but thanks for the info it could be useful to someone who has access to that msc.
Thank you for your comment too. I hope that useful. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.