Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

DBI::Oracle - fails on apache ( ORA-12154) - but works fine local

by Yaerox (Scribe)
on Apr 16, 2014 at 08:41 UTC ( [id://1082456]=perlquestion: print w/replies, xml ) Need Help??

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

My dbi_test.pl script works fine when doing local on terminal. When getting this on my apache I'm getting: dbi_test.pl: DBI connect('_DBNAME_','_DBUSER_',...) failed: ORA-12154: TNS:could not resolve the connect identifier specROR: OCIServerAttach) at /srv/www/cgi-bin/dbi_test.pl line 14.

My dbi_test.pl script is:

#!/usr/bin/perl -w use strict; use DBI; # Deklaration der lokalen Variablen my ($dbh); my $db_name = "_DBNAME_"; my $db_user = "_DBUSER_"; my $db_pwd = "_DBUSER_PWD_"; $dbh = DBI->connect("dbi:Oracle:$db_name", $db_user, $db_pwd, {RaiseEr +ror=>0, PrintError=>0 , AutoCommit => 0}); if (!defined $dbh) { print "DB-Connect-Fehler: $!\n"; exit; } my $hStatement = $dbh->prepare("SELECT count(*) FROM tbl"); $hStatement->execute; my @count = $hStatement->fetchrow_array(); print "Content-Type: text/html\n\n"; foreach (@count){ print "$count[0]\n"; } $hStatement->finish; $dbh->disconnect;

Already researched and tried to get where the problem is, but in case that i can use sqlplus without any problems it seems like the problem has to be with apache ... i did:

 perl -e 'use CGI ":all";print header;print "<pre>\n";map { print "$_ $ENV{$_}\n" } sort keys %ENV;print "</pre>\n";'

to get my Apache-Environment-Variables and imo everything should be okay. Oracle-Base, Oracle-Home, Tns-Admin, Ld-Library-Path everything is set ...

I don't have a clue how to go on ...

Replies are listed 'Best First'.
Re: DBI::Oracle - fails on apache ( ORA-12154) - but works fine local
by marto (Cardinal) on Apr 16, 2014 at 10:08 UTC

    "Oracle-Home"

    You should probably post the environment variables, those names look wrong. E.G. ORACLE_HOME rather than Oracle-Home. http://www.orafaq.com/wiki/ORACLE_HOME. If in doubt contact your system/database admin.

      Ohh, missunderstanding here ^^ ofc my environment variables are called: ORACLE_HOME, TNS_ADMIN, ORACLE_BASE and so on ... I just wrote it the other way here ;-)

Re: DBI::Oracle - fails on apache ( ORA-12154) - but works fine local
by Yaerox (Scribe) on Apr 16, 2014 at 12:22 UTC
    Wow, now I'm confused. Usually I'm using my connection-string from tnsnames.ora. I tried pasting the full string into my perl script and everything works fine. For me this looks like my apache doesn't read/use the tnsnames.ora ...
      I added the line Include /etc/apache/httpd.conf.local at the end of my /etc/apache/httpd.conf and my /etc/apache/httpd.conf.local looks like:
      SetEnv ORACLE_BASE=/usr/lib/oracle SetEnv ORACLE_HOME=/usr/lib/oracle/12.1/client SetEnv LD_LIBRARY_PATH=/usr/lib/mpi/gcc/openmpi/lib:/usr/lib/oracle/12 +.1/client/lib SetEnv TNS_ADMIN=/usr/lib/oracle/12.1/client SetEnv PATH=/usr/lib/oracle/12.1/client:$PATH
      and everything workes fine after retsarting ...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1082456]
Approved by marto
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-26 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found