URGENT: Pro*C, OCI Lda_Def and Fork Problem

From: Joe Spanicek <Joe.Spanicek_at_alcatel.com.au>
Date: 2000/03/03
Message-ID: <38BF29B0.A6A0AB5E_at_alcatel.com.au>#1/1


[Quoted] Hello All,

I am having problems using Pro*C OCI interface connecting to a Oracle database while forking processes.

The current situation is:

  1. Within the PARENT process I create a database connection by using GLOBAL Lda_Def variables, like:
           Lda_Def ldaP; /* For PARENT process */
           Lda_def ldaC; /* For CHILD process */

       I then use the the following Pro*C call to log me into the database:
           "EXEC SQL CONNECT :username IDENTIFIED BY :password;"

       Then immediately after this I make a call to 'sqllda' to sync the
       ProC and OCI data areas, like:

           sqllda(ldaP);

    b) The PARENT process is then able to execute Pro*C queries.

    c) The PARENT process then creates CHILD processes using the UNIX

       'fork' function.

    d) The CHILD process then also creates a database connection

       the same way the PARENT does in a) but stores its own LDA, like:

           sqllda(ldaC);

    e) All is well, where the PARENT and CHILD processes can execute

       Pro*C database queries using there own LDA connection.

    f) THE PROBLEM: When the CHILD process finishes and exits, the PARENT's

       database connection has also been closed or destroyed. That is, if
       the PARENT process executes a Pro*C query oracle errors are generated
       saying the database connection is no longer active.

       I assume the following is occuring:

           Since the PARENT forks off the CHILD process, the CHILD process
           inherits the PARENTS 'ldaP' structure which is already opened
           with a database connection.

           When the CHILD process exits, the PARENTS 'ldaP' structure or
           the Oracle connection is also destroyed. I want this connection
           to reamin active since the PARENT process requires to perform
           Pro*C queries.


The only bit of information I can find from Oracle docs regarding this is as follows:

    Note: Once you have established a connection, do not move the HDA or

          LDA data areas. The Oracle Server uses the address of these
          areas in processing OCI calls, and these addresses must remain
          the same during the life of a connection.

NOW, if the PARENT process makes a database connection using 'ldaP' and then forks off a CHILD. The CHILD can perform Pro*C queries using the 'ldaP' connection from the PARENT. BUT, the PARENT process and the CHILD process CAN NOT do a Pro*C query at the SAME time, Oracle complains about a two-task error.

My Question:

Is there any way around this problem ?

I can not find any OCI function call that will disassociate the CHILD process from the PARENTS 'ldaP' connection which will leave the PARENT's 'ldaP' connection intact.

Regards

Joe Spanicek Received on Fri Mar 03 2000 - 00:00:00 CET

Original text of this message