import ibm_db
try:
conn = ibm_db.connect("dsn=sample","user","password")
except:
print "no connection:", ibm_db.conn_errormsg()
else:
print "The connection was successful"
This works just fine in command line where I can successfully get the error message. I try to wrap this code in a function in following fashion.
def connect_to_db2():
max_try = 20
attempts = 0
database = "sample"
user = "user"
pword = "pword"
while attempts < max_try:
try:
conn = ibm_db.connect(database,user,pword)
except:
attempts += 1
print "Connection failed:", ibm_db.conn_errormsg()
else:
print "Connection was successfully established"
return conn
But I don't get any error message when the connection fails. Successful connections work just fine. Any idea what's going on?