perl - Error ORA-12154 on DBI->connect to Oracle database with Oracle Instant Client in Solaris 10 -


i've been pulling hair out on problem 2 days now:

i'm trying perl script interface oracle database. have new server i'd deploy application on. script worked.

here's i've done far:

placed tnsnames.ora file in instantclient/network/admin:

ls -la network/admin/ total 8 drwxrwxrwx   2 m staff        512 apr 19 09:54 . drwxrwxrwx   3 m staff        512 mar 28 15:56 .. -rwxrwxrwx   1 m staff        777 apr 19 09:54 tnsnames.ora 

my perl script looks this:

  12 use cgi;    13 use dbi;    14 use data::dumper;    15 use strict;    16     28 $env{oracle_home} = "/xxx/instantclient/";    29     32 $env{'ld_library_path'} = "xxx/instantclient/lib";    33     35 use dbd::oracle;    36     37 print "dbi::version: $dbi::version\n";    38 print "$dbd::oracle::version\n";    66 $dbh = dbi->connect("dbi:oracle:host=computer;port=1521;sid=mydatabase", "user", "pass");    67 $sth = $dbh->prepare("select sysdate dual");    68 $rv = $sth->execute;     69 dbi::dump_results($sth) if $rv;    70 $dbh->disconnect;    71     72 print "$database $dbuser $dbpassword \n";    73     74 $dbh = dbi->connect( $database, $dbuser, $dbpassword ) or die("problem line:\n$! , stopped"); 

this script produces output:

dbi::version: 1.609 dbd::oracle version: 1.24 '19-apr-13' 1 rows dbi:oracle:mydatabase user pass  dbi connect('mydatabase','user',...) failed: ora-12154: tns:could not resolve connect identifier specified (dbd error: ociserverattach) @ ./code.pl line 74 

my tnsnames.ora file contains following entry:

mydatabase =   (description =     (address = (protocol = tcp)(host = computer )(port = 1521))     (connect_data =       (service_name = service.computer.com)     )   ) 

this tnsnames.ora file has been copied working machine, i'm confident works.

the strange thing is, can connect code without using tnsnames.ora file, when try use it, breaks.

any suggestions?

not sure if help, following worked me:

to connect locally using tnsnames.ora (inside $oracle_home/network/admin directory):

my $db = dbi->connect( "dbi:oracle:mydatabase", "scott", "tiger" ); 

and connect not using tnsnames.ora:

my $db = dbi->connect("dbi:oracle:host=$host;sid=$sid;port=1521",$user,$passwd)     || die( $dbi::errstr . "\n" ); 

where $host, $sid have defined beforehand.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -