I am trying to connect to a db2 database in AS400 through python3 remotely. I am not able to get through the error message. I am running in spyder IDE in windows OS.
import ibm_db
conn=ibm_db.connect(f"DATABASE=xxxx;HOSTNAME=xxxx;PORT=21;PROTOCOL=TCPIP;UID=xxxxx;PWD=xxxxx;",'','')
connState = ibm_db.active(conn)
print(connState)
Error message
SQLCODE=-30081][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: "10.248.11.78". Communication function detecting the error: "connect". Protocol specific error code(s): "10061", "", "". SQLSTATE=08001
I did refer the document https://www.ibm.com/support/pages/sql30081n-tcpip-communication-errors but unable to make progress. I am new to this kind of connection and would appreciate the help.
Edit
As suggested in the comments. I used pyodbc
to successfully connect to db2 database and now I am trying to call a stored procedure.
My stored procedure has 3 required in(all numeric) and 2 out(both alphanumeric) parameters
import pyodbc
conn = pyodbc.connect('Driver={iSeries Access ODBC Driver}; '
'SYSTEM = xx.xxx.xx.xx;'
'Hostname=xxx; '
'Port=21; '
'Protocol=TCPIP; '
'Database=MYLIB; '
'UID=xxxxx; '
'PWD = xxxx;'
,autocommit=True)
cur = conn.cursor()
params = ("072220","0306529","10000")
cur.execute("{CALL MYLIB.MY_SP (@param1name=?, @param2name=?, @param3name=?)}",params)
Error message
('HY000', '[HY000] [IBM][System i Access ODBC Driver][DB2 for i5/OS]SQL0440 - Routine MY_SP in MYLIB not found with specified parameters. (-440) (SQLPrepare)')
Does this mean I am not passing my parameters right?
I figured the problem was the way I defined parameters. I need "0" for output parameters
import pyodbc
conn = pyodbc.connect('Driver={iSeries Access ODBC Driver}; '
'SYSTEM = xx.xxx.xx.xx;'
'Hostname=xxx; '
'Port=21; '
'Protocol=TCPIP; '
'Database=MYLIB; '
'UID=xxxxx; '
'PWD = xxxx;'
,autocommit=True)
cur = conn.cursor()
params = ("072220","0306529","10000",0,0)
cur.execute("{CALL MYLIB.MY_SP (?,?,?,?,?)}",params)