Segmentation error code pro * c to connect to the database

I wrote a simple pro * c program to test the connection to the database. The code:

int main()
{
    char *conn_string = "IDA/IDA@DBISPSS";
    int x = 10;
    printf("value of x is before db connection %d\n",x);
    printf(" conn_string %s \n",conn_string);
    EXEC SQL CONNECT :conn_string;
    EXEC SQL SELECT 1 INTO :x FROM DUAL;
    printf("value of x is %d\n",x);
    return 0;
}

The following commands I ran to create the exectuable (test_connection) code pro * c

proc test_connection.pc

cc -I${ORACLE_HOME}/precomp/public -c test_connection.c
cc   test_connection.o   -o test_connection -L$ORACLE_HOME/lib -lclntsh

and when I ran test_connection exe, the output

value of x is before db connection 10
conn_string IDA/IDA@DBISPSS
Segmentation fault

But the same code works well on a different Linux machine and a Solaris machine.

Why is there a segmentation error?

+3
source share
2 answers

I tested on HPUX 11.11 / Oracle 11 and worked fine. I do not see any problems, but I will try some changes:

  • Declare 'x' in DECLARE PERMISSION:

    EXEC SQL BEGIN DECLARE SECTION;
    int x = 0;
    EXEC SQL END DECLARE SECTION;
    
  • Try this connection command:

    EXEC SQL BEGIN DECLARE SECTION;
    char *user = "abc", *password = "123", *database="base";
    EXEC SQL END DECLARE SECTION;
    EXEC SQL DECLARE BASE_HANDLE DATABASE;
    ...
    EXEC SQL CONNECT :user IDENTIFIED BY :password AT BASE_HANDLE USING :database;
    ...
    EXEC SQL AT BASE_HANDLE SELECT 1...
    
  • Insert printf("here 1");between EXEC SQL CONNECT...and EXEC SQL SELECT ...to see where SEGFAULT is being called.

+3

, . - , () , , Oracle 32- . , Oracle - 64- . , 32- . 32- Pro * C.

+1

All Articles