ibm_db.conn_errormsg() returns nothing from within a function definition

24 views
Skip to first unread message

Saurabh

unread,
Mar 2, 2012, 5:30:24 PM3/2/12
to ibm...@googlegroups.com
I'm trying out the Example 1 sample code from here:  http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=%2Fcom.ibm.swg.im.dbclient.python.doc%2Fdoc%2Fc0054395.html

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?

Rahul

unread,
Mar 4, 2012, 2:33:36 AM3/4/12
to ibm_db
Hi Saurabh,
I tried to regenerate your issue with the same test case you have
provided but it works fine with me.
Please give us the info about your platforms like python version,
Operating System, DB2 version etc.

Please also provide the DB2 trace which would help us more to find the
problem.
If you don't know how to take DB2 trace then refer following link
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.apdv.cli.doc/doc/c0007959.html.

Thanks,
Rahul Priyadarshi

On Mar 3, 3:30 am, Saurabh <saurab...@live.com> wrote:
> I'm trying out the Example 1 sample code from here:  http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp?topic=...

Saurabh S

unread,
Mar 5, 2012, 2:05:39 PM3/5/12
to ibm...@googlegroups.com
Hi Rahul,

Thanks for the reply. I just tried writing that function again, and it works now. I am getting the error messages as expected. Maybe there was a temporary problem with the database.

Sorry for the bother!

Regards,
Saurabh

> Date: Sat, 3 Mar 2012 23:33:36 -0800
> Subject: [ibm_db:589] Re: ibm_db.conn_errormsg() returns nothing from within a function definition
> From: rahul.pr...@in.ibm.com
> To: ibm...@googlegroups.com
> --
> You received this message because you are subscribed to the Google Groups "ibm_db" group.
> To post to this group, send email to ibm...@googlegroups.com.
> To unsubscribe from this group, send email to ibm_db+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/ibm_db?hl=en.
>
Reply all
Reply to author
Forward
0 new messages