guo lei li
guo lei li

Reputation: 15

DB2 shell run issue

When i run shell in DB2 instance.

VAR=`db2 CONNECT TO ${DBNAME} ${DBUSRSTR}`

if [ ! $? -eq 0 ]; then
  logErr ${MSG002E}
  logErr ${VAR}
  exit 2
fi
logInfo "【2】 DB2 connect " $?
logInfo ${VAR}


db2 set current schema TEST
if [ ! $? -eq 0 ]; then
  logErr ${MSG002E}
  exit 2
fi

2019-06-17 03:32:03,123 INFO [test.sh] 【2】 DB2 connect: 0
2019-06-17 03:32:03,124 INFO [test.sh] Database Connection Information Database server = DB2/LINUXX8664 10.5.5 SQL authorization ID = DB2INST1 Local database alias = TEST
DB21034E  The command was processed as an SQL statement because it was not a
valid Command Line Processor command.  During SQL processing it returned:
SQL1024N  A database connection does not exist.  SQLSTATE=08003
2019-06-17 03:32:04,127 ERR [test.sh] 

I don't know why it's seemed to connect success .. but can't execute sql?

I try it in the db2 command.

db2 =>

It was working fine. But in the shell. it's failed.

Upvotes: 0

Views: 512

Answers (1)

data_henrik
data_henrik

Reputation: 17118

The result is expected. The Db2 command line processor opens up a new front-end process whenever it is invoked. Depending on how it is invoked, either the same or a different back-end process is used. If it is different, it would be a different connection.

Because you evaluate the call to Db2 in a subprocess of your shell script process, each time a different back-end process is involved. Hence, you would need a new database connection.

Try to open the connection as part of the shell process, not a subprocess. You need to redesign the flow.

Upvotes: 1

Related Questions