DB2 Connect issue

Hi

i m trying to connect DB2 via unix. it is successfully connect. but the connect is getting disconnect .

below is the query ,

countvalue=$(db2 "connect to  <Database> user  <username>  using <Password>"  | db2 -x  'select count(*)  from <tablename>' ); echo $countvalue

while execute this query it returns countvalue properly but not all the times. sometimes it says the below error,

SQL1024N A database connection does not exist. SQLSTATE=08003

Do have any option to make the connect stable.

Thanks in Advance,

Baski

I suspect the error means what it says, that the database doesn't exist. Check the value of the database string to make sure it's always correct. Make sure something else isn't messing with it while you're trying to connect.

I'm no DB2 expert, but... why are you piping one db2 call into the other?
I bet you meant something like this with the here-doc - adjust for the proper DB2 syntax:

countvalue=$(db2 <<EOF
     connect to  <Database> user  <username>   using <Password>
     select count(*)  from  <tablename>
EOF
); echo $countvalue.