I am working on a Perl program that connects to an Informix database. The Perl program may fork and execute an external program that also talks to the database. The external programs are compiled esql C code. The Perl program and the external program communicate via a UNIX socket, and the Perl program blocks until the external program finishes its business.

For some external programs it works, and for others sqlcode -349 "Database not selected yet" happens on the first esql statement attempted in the external program. From what I've read, child processes inherit database connections from the parent, so this error should never happen. The Perl program always has a connection to the database established before calling the external program.

The program is DBIx::Perform version 0.693 (in the authors section in CPAN under my name, bkchapin, as the original author of DBIx::Perform has not sanctioned my changes). The environment is HP-UX 11.11, Informix version 9.50C1, Perl 5.8.8 compiled with gcc, and gcc version 3.4.6. Originally, esql used the native C compiler, but I modified a copy to use gcc. esql for gcc is what I'm using now.

Any insight? Here comes confusion. I've been reading that some databases keep some kind of connection info variously called a "session ID", "connection ID", or "database handle" (so, an integer?) and I should fetch this information somehow in both parent and child and see if it's present and the same. I can't see that being the $dbh in $dbh = DBI->connect(...). Perhaps it's something like $dbh->{ix_ConnectionName}, but that is a name, not some kind of integer value like I'd expect a handle to be. Maybe there's some database query that would return this info, but that doesn't seem right either because if the child doesn't have a handle with which to connect, it can't very well query the database for a handle. Then there's $sth, and perhaps the 's' in that name is for "session" and I have "session ID" and "connection ID" conflated above? If I get this info, then there's some flag for "onstat" or some other db utlitity I can use to check things. No, I'm not a database guru, but I do well enough most of the time.


In reply to DB connection after fork, exec by bkchapin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.