Re: core dump using Pro*C on CONNECT

From: Andy Finkenstadt <kahuna_at_panix.com>
Date: Thu, 24 Jul 2003 19:11:43 +0000 (UTC)
Message-ID: <bfpb1f$hc0$1_at_reader1.panix.com>


In <3148847.1059070191_at_dbforums.com> thumor <member34030_at_dbforums.com> writes:
>Line of code in my Pro*C file:

><--BEGIN-->

> strcpy(Username, user_id);
> strcpy(Userpass, user_pw);
> strcpy(DBname, db_name);

> strcat(Username, '\0');
> strcat(Userpass, '\0');
> strcat(DBname, '\0');

[Quoted] Those last strcat's are not needed as strcpy already copies in the null terminating byte. This has nothing to do with the problem, though.

>EXEC SQL CONNECT :Username IDENTIFIED BY :Userpass AT DB_NAME
>USING :DBname;

> if (sqlca.sqlcode != 0)
> {
> sprintf(Log_Msg, "Error %d (%s) Connecting Database
> ",sqlca.sqlcode,sqlca.sqlerrm);
> Log_Message(Waste_Log, "pods_init", FATAL, Log_Msg);
> }
> else
> {
> sprintf(Log_Msg, "Connection to Database Successful");
> Log_Message(Waste_Log, "pods_init", INFORM, Log_Msg);
> };
><--- End -->

What are the definitions of DBname, Username and Userpass? If they are VARCHARs declared inside a DECLARE SECTION, then you should be using:

EXEC SQL BEGIN DECLARE SECTION;
VARCHAR Username[32];
VARCHAR Userpass[32];
VARCHAR DBname[32];
EXEC SQL END DECLARE SECTION; strncpy( Username.arr, user_id, sizeof(Username.arr)); Username.len = strlen(user_id);

strncpy( Userpass.arr, user_pw, sizeof(Userpass.arr)); Userpass.len = strlen(user_pw);

strncpy( DBname.arr, db_name, sizeof(DBname.arr)); DBname.len = strlen(db_name);

Andy

-- 
Andrew Finkenstadt (http://www.finkenstadt.com/andy/)
Received on Thu Jul 24 2003 - 21:11:43 CEST

Original text of this message