2

I try to check the availability of a DB2 Instance via the db2cli-utility, as follows

db2cli execsql -user USER -passwd PASSWD -connstring DATABASE:HOST:PORT

(with actual values for the uppercased text). I would expect this to connect to HOST:PORT, using the credentials USER and PASSWD, and to switch to database DATABASE.

As a result i get

SQLError: rc = 0 (SQL_SUCCESS) 
SQLGetDiagRec: SQLState     : 08001
      fNativeError : -1024
      szErrorMsg   : [IBM][CLI Driver] SQL1024N  A database connection does not exist.      SQLSTATE=08003
      cbErrorMsg   : 82

But: these values WORK, on the same machine, if i use them as credentials in applications that connect to DB2, so i would expect that i get a connection with the given command.

My Question is: am i using db2cli wrong?

keppla
  • 1,753
  • 2
  • 15
  • 29
  • Did you have a chance to look in the manual? It explains how to correctly specify `db2cli` parameters. (Hint: you may want to choose the `validate` subcommand.) – mustaccio Jun 26 '14 at 14:36
  • i had, albeit i am a little confused by it. i expected to get a shell where i may type random sql on success. i'm looking into validate, thank you – keppla Jun 26 '14 at 14:40

2 Answers2

2

You are using wrong connection string as well as options. Check correct command syntax by running "db2cli execsql -help" command.

You can use -user and -passwd option with -dsn option only. If you are using connection string, then uid and pwd should be part of -connstring option value. Also, the syntax of connection string is wrong. It must be a pair of keyword and value separated by semicolon and enclosed by quotes like "key1=val1;key2=val2;key3=val3". The correct command that you should use is:

db2cli execsql -connstring "DATABASE=dbname;HOSTNAME=hostname;PORT=portnumber;UID=userid;PWD=passwd"

The output for me is as below:

$ db2cli execsql -connstring "database=bluemix;hostname=192.168.1.20;port=50000;uid=myuid;pwd=mydbpassword"
IBM DATABASE 2 Interactive CLI Sample Program
(C) COPYRIGHT International Business Machines Corp. 1993,1996 
All Rights Reserved
Licensed Materials - Property of IBM
US Government Users Restricted Rights - Use, duplication or
disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
> select 'bluemix' from sysibm.sysdummy1
select 'bluemix' from sysibm.sysdummy1
FetchAll:  Columns: 1
  1
  bluemix
FetchAll: 1 rows fetched.
> quit

$

To know the instance name, you should run db2level command.

$ db2level
DB21085I  This instance or install (instance name, where applicable: "bimaljha") uses
"64" bits and DB2 code release "SQL10054" with level identifier "0605010E".
Informational tokens are "DB2 v10.5.0.4", "s140813", "IP23623", and Fix Pack "4".
Product is installed at "/home/bimaljha/sqllib".
Bimal Jha
  • 391
  • 2
  • 14
0

you can try validate connect like below(it will make you sure if connection is successful)

db2cli validate -dsn sample -connect

db2cli.ini :

[sample]

hostname=host

pwd=password

port=portnumber

PROTOCOL=TCPIP

database=dbname

uid=username

Anand
  • 621
  • 3
  • 9
  • 31