Re: Pro*C connect problem

From: <bamon_at_ocvaxc.cc.oberlin.edu>
Date: 15 Apr 93 13:28:54 EDT
Message-ID: <1993Apr15.132854.1_at_ocvaxc.cc.oberlin.edu>


In article <1993Apr14.144354.20172_at_icf.hrb.com>, gml_at_icf.hrb.com (Gretchen M. Lenze) writes:
> Hello....
>
> I am writing an application in Pro*C which (among other
> things (= ) connects to the database. In this application I am
> reading the Oracle username/password from a UNIX ASCII file. The
> problem I'm having is that every time the username/password string
> changes (this happens often), I have to go back in to the code and
> change the length of the host array declaration. Currently I can't
> do a connect if the host array isn't the same length as the
> username/password sting. Does anyone know a good solution to this
> problem?

This shouldn't be a problem. Declare the username and password as VARCHARs that are large enough to handle the largest possible values, then be sure to set the userid.len and password.len to the current length of the values read in from the file (or passed in as parameters.

EXEC SQL BEGIN DECLARE SECTION;
   VARCHAR userid[20];
   VARCHAR password[20];
EXEC SQL END DECLARE SECTION; EXEC SQL INCLUDE ORA_PROC:SQLCA;
EXEC SQL INCLUDE ORA_PROC:SQLDA;

/**************************

  M A I N P R O G R A M
***************************/

main(argc,argv,envp)
 int argc;
 char *argv[];
 char *envp[];

 {

  /****************************

    Declare local C variables
    in this spot.
  *****************************/

  /********************

    Connect to Oracle
  *********************/

  EXEC SQL WHENEVER SQLWARNING GO TO ERROR_RTN;   EXEC SQL WHENEVER SQLERROR GO TO ERROR_RTN;    strcpy(userid.arr,argv[1]);
   userid.len = strlen(userid.arr);

   strcpy(password.arr,argv[2]);
   password.len = strlen(password.arr);

   EXEC SQL CONNECT :userid IDENTIFIED BY :password;

Or, alternatively, use the "/" username/password and implement the ops$ oracle usernames.

  /********************

    Connect to Oracle
  *********************/

  EXEC SQL WHENEVER SQLWARNING GO TO ERROR_RTN;   EXEC SQL WHENEVER SQLERROR GO TO ERROR_RTN;   strcpy(userid.arr,"/");
  userid.len = strlen(userid.arr);

  EXEC SQL CONNECT :userid;


Jennifer R. Amon            PHONE: (216) 775-6987   
Houck Computing Center        FAX: (216) 775-8573    
Oberlin College          
Oberlin, OH 44074        INTERNET: bamon_at_ocvaxc.cc.oberlin.edu
_____________________________________________________________________
Received on Thu Apr 15 1993 - 19:28:54 CEST

Original text of this message