thil has asked for the wisdom of the Perl Monks concerning the following question:

Hi,

I think this is the right place to talk about this matter. I have a perl script which accesses the Oracle database. Now I get a strange error there, saying that the query prepare failed. The exact error is as follows.

DBD::Oracle::db prepare failed: ERROR Database disconnected [for Statement ...


My problem is, this only happens when I go to one script from another script. (i.e. In the first script I can access the database and it works fine. But when the navigation moves to the second script, the query preparation doesn't work. But the database connects successfully).

It doesn't give errors in the query ( eg:table does not exist) even when I put a completely incorrect query. It simply says that the prepare failed. And also this doesn't work even for a simple query like, 'select ename from company'.

can anybody help me with this?

Thanks,

Thilani

Replies are listed 'Best First'.
Re: Perl $dbh->prepare failed
by blue_cowdawg (Monsignor) on Sep 12, 2006 at 12:33 UTC
        My problem is, this only happens when I go to one script from another script.

    Reading that statement sends off alarm bells. What do you mean by that statement? How are you going from one script to the other?

    The error you are citing would lead me to believe that you are not preparing a statement against a valid database handle.

    Of course... I'm taking pot shots in the dark here given I don't have any code to go on here...


    Peter L. Berghold -- Unix Professional
    Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg

      Yes.. I know. there isn't any code information attached to my question. simply because the codes are long and has a lot of sub routines coming from various Modules. :). sorry for that.

      Going from one script to another script means this,
      User first seeks for employers. That is the task of the first script. And from the result page, users can click on the employer name and go to the employer details page(second script). In the second script, the database handler is newly created if it is not alive.
            In the second script, the database handler is newly created if it is not alive.

        How are you testing for "alive?" Unless you are using mod_perl or some method of pooling your database handles I'd say you should be opening your handles unconditionally in your second script.


        Peter L. Berghold -- Unix Professional
        Peter -at- Berghold -dot- Net; AOL IM redcowdawg Yahoo IM: blue_cowdawg
Re: Perl $dbh->prepare failed
by aquarium (Curate) on Sep 12, 2006 at 12:22 UTC
    just a guess..your database handle is out of scope when you're in the second script. you'll need to pass the handle to the second script..by reference.
    the hardest line to type correctly is: stty erase ^H
      The database handler is again created in the second script. The connection is alive till the error occurs.