Error when using ibm_db.connect(), with dynamic connection string.

307 views
Skip to first unread message

Phani Kiran Siddineni

unread,
Jan 22, 2018, 1:16:56 AM1/22/18
to ibm_db
Hi ,

I 'm encountering error when connecting to ibm_db (DB2 on zos with variables in connection string. hardcoded connection string works fine.

For ex:
ibm_db.connect("DATABASE=dbname;HOSTNAME=host;PORT=port;PROTOCOL=tcpip;uid=uid;PWD=pwd;", "", "")   - This works fine
But
connstr = '''"DATABASE={0};HOSTNAME={1};PORT={2};PROTOCOL=tcpip;uid={3};PWD={4};"'''.format(db, self.sid, port,  self.uid, self.pwd)
ibm_db.connect(connstr, "", "")
- This doesnt work and throws error Exception: [IBM][CLI Driver] CLI0199E  Invalid connection string attribute. SQLSTATE=08001 SQLCODE=-99999

there should be a way to pass variables to connection string right ? What am I Missing here ?

Saba Kauser

unread,
Jan 22, 2018, 2:02:06 AM1/22/18
to ibm_db
Try like this: config.py is a file under ibm_db package. You can also specify values instead.
conn_str = "DATABASE=%s;HOSTNAME=%s;PORT=%d;PROTOCOL=TCPIP;UID=%s;PWD=%s;" % (config.database, config.hostname, config.port, config.user, config.password)

Thanks,
Saba.
Reply all
Reply to author
Forward
0 new messages