Re: core dump using Pro*C on CONNECT
Date: Tue, 29 Jul 2003 17:33:09 +0200
Message-ID: <bg643m$gte$1_at_news.fujitsu-siemens.com>
"thumor" <member34030_at_dbforums.com> schrieb im Newsbeitrag
news:3157120.1059407316_at_dbforums.com...
>
> Originally posted by Volker Hetzer
> > "thumor" schrieb im Newsbeitrag
> > news:3148847.1059070191_at_dbforums.com"]news:3148847.1059070191_at_d-
> > bforums.com[/url]...
> > > Line of code in my Pro*C file:
> > >
> > > strcpy(Username, user_id);
> > > strcpy(Userpass, user_pw);
> > > strcpy(DBname, db_name);
> > > strcat(Username, '\0');
> > > strcat(Userpass, '\0');
> > > strcat(DBname, '\0');
> > > EXEC SQL CONNECT :Username IDENTIFIED BY :Userpass AT
> > DB_NAME
> > > USING :DBname;
> > Had the same problem on linux. Workaround:
> > EXEC SQL CONNECT :Username_at_DBname IDENTIFIED BY :Userpass
> >
> > Lots of Greetings!
> > Volker
>
> Should this be like
> EXEC SQL CONNECT :Username_at_:DBname IDENTIFIED BY :Userpass;
>
> Note- The colon before DBname.
This is my file modified from the demos directory.
/*
* sample1.pc * * Prompts the user for an employee number, * then queries the emp table for the employee's * name, salary and commission. Uses indicator * variables (in an indicator struct) to determine * if the commission is NULL. * */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include <sqlda.h>
#include <sqlcpr.h>
#include <sqlca.h>
/* Define constants for VARCHAR lengths. */
#define UNAME_LEN 20 #define PWD_LEN 40 #define DB_LEN 40
/* Declare variables. No declare section is needed if MODE=ORACLE. */
VARCHAR username[UNAME_LEN]; /* VARCHAR is an Oracle-supplied struct */ varchar password[PWD_LEN]; /* varchar can be in lower case also. */ varchar db[DB_LEN]; /* varchar can be in lower case also. */
/* Declare error handling function. */
void sql_error(msg)
char *msg;
{
char err_msg[128];
size_t buf_len, msg_len;
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf("\n%s\n", msg);
buf_len = sizeof (err_msg);
sqlglm(err_msg, &buf_len, &msg_len);
printf("%.*s\n", msg_len, err_msg);
EXEC SQL ROLLBACK RELEASE;
exit(EXIT_FAILURE);
}
int main(int argc,char*argv[])
{
[Quoted] strncpy((char *) username.arr, "SPIELPLATZ_at_ecadtst", UNAME_LEN);
username.len = (unsigned short) strlen((char *) username.arr);
strncpy((char *) password.arr, "SPIELPLATZ", PWD_LEN);
password.len = (unsigned short) strlen((char *) password.arr);
strncpy((char *) db.arr, "ecadtst", DB_LEN);
db.len = (unsigned short) strlen((char *) db.arr);
EXEC SQL WHENEVER SQLERROR DO sql_error("ORACLE error--\n");
EXEC SQL CONNECT :username IDENTIFIED BY :password ;
printf("\nConnected to ORACLE as user: %s\n", username.arr);
exit(EXIT_SUCCESS);
}
Received on Tue Jul 29 2003 - 17:33:09 CEST