Re: Connecting to Oracle from a ProC program.

From: <nilesh_at_cheerful.com>
Date: 1998/03/06
Message-ID: <6dqh8t$i2n$1_at_nnrp1.dejanews.com>#1/1


Hey James, I have not worked on Oracle 8 (only with Oracle 7as of yet) but I think the problem is that the varchar arrays (.arr) ar not being explicitly null terminated by a \0.

I think this should work:

#include<stdio.h.
#include<stdlib.h>
/*Other Headers that you want to*/

/* Function Prototypes and global declarations*/

/*Include the SQL Communication Area*/
exec sql include sqlca;

int main(void)
{

/* Decalre the host variables for*/

	exec sql begin declare section;
	  varchar2 username(30);
	  varchar2 password(30);
	  varchar2 servername(30);
	exec sql end declaration;

/* Other Declarations */

/*Get The usrname*/
printf("Please Enter USERNAME\n"); scanf("%s", user_name.arr); username.arr[strlen(username.arr)] = '\0";
/*Get The Password*/
printf("Please Enter Oracle PASSWORD\n"); scanf("%s", password.arr); password.arr[strlen(password.arr)]="\0";
/*Get The Servername to connect to*/
printf("Please Enter Database Name to connect to\n"); scanf("%s",servername.arr); servername.len[strlen(servername.arr)]="\0";
/*Connect To the database*/
EXEC SQL CONNECT :username IDENTIFIED BY :password using :servername; if (sqlca.sqlcode !=0) { /* 1,-1 for error/warning */ printf("\nUnable To Establish Connection\nAbnormal Program Exit"); return(-1); } else { /* the rest of the code*/ return 0; }

}/*end of int main(void)*/

Hope this helps,

Nilesh Porwal,
nilesh_at_cheerful.com

In article <6dmh7d$9ms$1_at_m1.cs.man.ac.uk>,   chuaj5_at_cs.man.ac.uk wrote:

>
> Hi..
>
> I was wondering if anyone could help me in this problem. I'm very simply trying to connect up to my Oracle 8 server by calling from my ProC program but after returning it my username and password, it keeps going back in a loop and prompting me for my username and password again. The C program to do that is below:-
>
> void connect()
> {
> 	char user_name[MAXSIZE];
> 	char passwd[MAXSIZE];
>
>    	printf("Please Enter USERNAME\n");
>    	scanf("%s", user_name);
>    	strncpy((char *) SQL_username.arr, user_name, MAXSIZE);
> 	SQL_username.len = strlen((char *) SQL_username.arr);
>
> 	printf("Please Enter Oracle PASSWORD\n");
>    	scanf("%s", passwd);
> 	strncpy((char *) SQL_passwd.arr, passwd, MAXSIZE);
> 	SQL_passwd.len = strlen((char *) SQL_passwd.arr);
>
> 	EXEC SQL WHENEVER SQLERROR DO sqlerror("Cannot connect to ORACLE database!");
>
> 	EXEC SQL CONNECT :SQL_username IDENTIFIED BY :SQL_passwd;
> 	printf("\nConnected to Oracle as user: %s\n", SQL_username.arr);
> }
>
> A sqlnet.log file is then generated with the errors in it.
>
> Any ideas or suggestions will be greatly appreciated.
> Thanks
>
> James.
>
>


-----== Posted via Deja News, The Leader in Internet Discussion ==----- http://www.dejanews.com/ Now offering spam-free web-based newsreading Received on Fri Mar 06 1998 - 00:00:00 CET

Original text of this message