CLI Multiple Instance Trouble 
Author Message
 CLI Multiple Instance Trouble

I am using DB2 v6 CLI on AIX. My program needs to
connect to one database, close it and then
connect to a second database in a different
instance. I get the error "SQL1403N The username
and/or password supplied is incorrect". The
username and password are purposely not specified
so that DB2 will use the security context of the
current user. I boiled my problem down to the
following broken code. If lines 12 to 15 are
removed, the program works! How do I get around
this without explicitly setting the username and
password (security risk)? Also, is my usage of
putenv() the correct approach here? Thanks,

    +1  #include <stdio.h>
    +2  #include "sqlcli1.h"
    +3
    +4  void dberror(SQLSMALLINT htype, SQLHANDLE
hndl);
    +5
    +6
    +7  int main(int argc, char *argv[])
    +8  {
    +9     SQLHDBC hdbc;
   +10     SQLHENV henv;
   +11
   +12     putenv("DB2INSTANCE=inst01");
   +13
   +14     SQLAllocHandle(SQL_HANDLE_ENV,
SQL_NULL_HANDLE, &henv);
   +15     SQLFreeHandle(SQL_HANDLE_ENV, henv);
   +16
   +17     putenv("DB2INSTANCE=inst02");
   +18
   +19     SQLAllocHandle(SQL_HANDLE_ENV,
SQL_NULL_HANDLE, &henv);
   +20     SQLAllocHandle(SQL_HANDLE_DBC, henv,
&hdbc);
   +21
   +22     if (SQLConnect(hdbc, "db02", SQL_NTS,
   +23        NULL, SQL_NTS, NULL, SQL_NTS) !=
SQL_SUCCESS)
   +24     {
   +25        fprintf(stderr, "Could not connect
to ctndcd01\n");
   +26        dberror(SQL_HANDLE_DBC, hdbc);
   +27
   +28        SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
   +29        SQLFreeHandle(SQL_HANDLE_ENV, henv);
   +30
   +31        return (1);
   +32     }
   +33
   +34     SQLDisconnect(hdbc);
   +35
   +36     SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
   +37     SQLFreeHandle(SQL_HANDLE_ENV, henv);
   +38
   +39     return (0);
   +40  }
   +41
   +42
   +43  void dberror(SQLSMALLINT htype, SQLHANDLE
hndl)
   +44  {
   +45     SQLCHAR   buffer
[SQL_MAX_MESSAGE_LENGTH + 1];
   +46     SQLCHAR sqlstate[SQL_SQLSTATE_SIZE +
1];
   +47     SQLINTEGER sqlcode;
   +48     SQLSMALLINT length, i;
   +49
   +50     i = 1;
   +51     while (SQLGetDiagRec(htype, hndl, i,
sqlstate, &sqlcode, buffer,
   +52        SQL_MAX_MESSAGE_LENGTH + 1,
&length) == SQL_SUCCESS)
   +53     {
   +54        fprintf(stderr, "dberror: sqlstate
[%s], sqlcode [%ld]: %s",
   +55           sqlstate, sqlcode, buffer);
   +56        i++;
   +57     }
   +58  }
   +59

Sent via Deja.com
http://www.***.com/



Sat, 05 Jul 2003 10:14:49 GMT
 
 [ 1 post ] 

 Relevant Pages 

1. how to differenciate multiple instances of a CLI task

2. Advice needed: Multiple instances vs Multiple users in 1 instance

3. Single-Instance Cluster vs Multiple-Instance Cluster

4. Moving a Single Instance to a Multiple Instance Cluster

5. Changing DB2 instance in multiple instance environment

6. Multiple Databases/Multiple Instances

7. Multiple Instances or Multiple Servers

8. Multiple Schemas vs. Multiple Instances

9. Multiple Instances Vs Multiple Servers

10. multiple users or multiple oracle instance of the same database

11. Trouble with Informix 7.3 on Solaris and CLI 2.5

12. Informix-CLI 2.50 & Informix-Net trouble


 
Powered by phpBB® Forum Software