I am using a c++ program to call some precompiled package (Embedded SQL) to connect to db2, do some selection, disconnect.

When I was using DB2 v5, the program was okay. While when I use verison 8.1, My program is like this

attach ctx (call API sqleAttachToCtx)
connect to table
do selection
deattach ctx (call API sqleDetachFromCtx)

attach ctx
connect to table ---------------> -808

That means for 1st round of attaching, connecting, disconnecting and deattaching, it works ok. But for 2nd round, I get the -808 error when trying to connect to database. If I elimiate all the attach/deattach ctx statements, it will work. Please help.