2 Replies Latest reply: Jun 5, 2012 4:47 AM by 941419 RSS

    DBD::Oracle & Instant client - don't find tnsnames.ora


      I'm trying to use tns names in Perl scripts to connect with Instant client. I always get the ORA-12154 error when connecting with Perl :

      ORA-12154: TNS:could not resolve the connect identifier specified (DBD ERROR: OCIServerAttach).

      The perl command that raise the error is :

      +$dbh = DBI->connect("dbi:Oracle:MYDB","user","password") or die $DBI::errstr."\n";+

      I checked my Oracle installation and everything seems fine. Connection with sqlplus work without problem using the same connection string (sqlplus user/passowrd@MYDB).

      I stat'ed my tnsnames.ora file to check if it's accessed : it is with sqlplus, but not with my perl script.

      Instant Client has been installed with the zip files made available by Oracle (not RPM). ORACLE_HOME points to the installation directory and tnsnames.ora is located in $ORACLE_HOME//network/admin/. Server is a Red Hat Entreprise 5.

      In my knowledge DBD::Oracle use OCI so there should not have difference between sqlplus and DBD::Oracle. Am I wrong ? Anyone have had this problem before ?

      Thanks for your help

        • 1. Re: DBD::Oracle & Instant client - don't find tnsnames.ora
          Laurenz Albe
          Yes, DBD::Oracle uses OCI and it should work.

          I suspect that ORACLE_HOME is not set in DBD::Oracle's environment.

          How is DBD::Oracle invoked? From a web server? From the command line?
          Try to output the Oracle environment with Perl before you call DBD::Oracle.

          Laurenz Albe
          • 2. Re: DBD::Oracle & Instant client - don't find tnsnames.ora

            Environment variables was correctly defined, but your comment put me on the right track.
            I printed the %ENV content to check ORACLE_HOME which was OK.
            I check the directory and remind I put a sqlnet.ora file in the same directory than tnsnames.ora with the followin content :

            AUTOMATIC_IPC = OFF
            names.directory_path = (TNSNAMES)
            names.default_domain = world
            name.default_zone = world

            I removed this file and everything is ok now. I don't really know what this file is used for, but if I keep it online and change MYDB in the connection name to MYDB.world, it worked. I think I have to learn more about names...

            Thanks for your help anyway !