Re: How to open a 2nd DB without closing the 1st in ESQL/C?
Posted in 1995
Topics: Connectivity: ESQL/C, 4GL & Embedded SQL
In article <3nj24q$678@eos.ap.org>,
Rajesh N. Malhotra <malhotra@eos.ap.org> wrote:
>Informix Gurus,
>
> How can one open a second DB without closing the first?
>Our application is written in ESQL/C, keeping our database open with
>several resources allocated (Statements defined, cursors declared etc).
>Now I need to open the sysmaster db briefly, query it and close it,
>but I do not want to close our main database (thus freeing up the resources).
>
>The way I do it is
>
> if ((cpid = fork()) == -1)
> perror("fork");
>
> if (cpid == 0)
> { /* Child process */
> Open_Sysmaster_DB(); /* thereby closing our main db */
> Query_Sysmaster_DB();
> Close_Sysmaster_DB();
> exit(0);
> }
> else
> wait(cpid);
>
>The child works fine and exits, and the parent continues. But now when the
>parent tries to access a preallocated resource (fetch from an open
>cursor), it just hangs there and never returns.
>
> Have those resources been freed when the chile opened sysmaster
>(thereby closing our main db)? The child should inherit the parent's
>environment, and therefore close the main DB in its own process space.
>The main DB in the parent's process space should still be open.
>
> What am I doing wring here? Any and all responses appreciated.
[SNIP]
You should be using the sqldetach() function in the child. Remember, since
you're not doing an exec() the child is running in the same address space as
the parent. Thus the child's SQL statements are messing up memory in the
parent. The call to sqldetach() will fix this. See chapter #8 of the
Informix ESQL/C Programmers Manual (at least it's chapter #8 in the 5.0
manual).
There is another (better) way to do what you want. Instead of opening
multiple connections just use the fully qualified name for the table in
sysmaster.
In the parent you can say something like:
select *
from sysmaster@servername:table_name
You don't need to have multiple connections in informix.
--
Greg C. Faulk Database Administrator
TRW Financial Systems Document Imaging Systems
300 Lakeside Drive Phone: (510) 645-3655, Fax: (510) 645-3311
Oakland CA 94612-3540 E-mail: gregf@tfs.com