本文介绍了DBI上的错误ORA-12154->使用Solaris 10中的Oracle Instant Client连接到Oracle数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为这个问题拉了两天了:

I've been pulling my hair out over this problem for two days now:

我正在尝试获取一个Perl脚本来与Oracle数据库交互.我有一个新服务器要在其上部署我的应用程序.该脚本以前有效.

I'm trying to get a perl script to interface with an Oracle database. I have a new server I'd like to deploy my application on. This script previously worked.

这是我到目前为止所做的:

Here's what I've done so far:

将我的tnsnames.ora文件放置在Instantclient/network/admin中:

Placed my 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

我的Perl脚本如下:

My Perl script looks like 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 my $dbh = DBI->connect("dbi:Oracle:host=computer;port=1521;sid=mydatabase", "user", "pass");
   67 my $sth = $dbh->prepare("SELECT sysdate FROM dual");
   68 my $rv = $sth->execute;
   69 DBI::dump_results($sth) if $rv;
   70 $dbh->disconnect;
   71
   72 print "$database $dbUser $dbPassword \n";
   73
   74 my $dbh = DBI->connect( $database, $dbUser, $dbPassword ) or die("PROBLEM WITH LINE:\n$! , stopped");

此脚本产生以下输出:

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 the connect identifier specified (DBD ERROR: OCIServerAttach) at ./code.pl line 74

我的tnsnames.ora文件包含以下条目:

My tnsnames.ora file contains the following entry:

mydatabase =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = computer )(PORT = 1521))
    (CONNECT_DATA =
      (SERVICE_NAME = service.computer.com)
    )
  )

此tnsnames.ora文件是从正在运行的计算机上复制的,因此我确信它可以正常工作.

This tnsnames.ora file has been copied from a working machine, so I'm confident it works.

奇怪的是,我可以不使用tnsnames.ora文件而连接到代码,但是当我尝试使用它时,它就会中断.

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

有什么建议吗?

推荐答案

不确定是否有帮助,但是以下内容对我有用:

Not sure if it help, but the following worked for me:

使用tnsnames.ora(在$ ORACLE_HOME/network/admin目录中)在本地连接:

TO connect locally using tnsnames.ora (inside $ORACLE_HOME/network/admin directory):

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

,并且不使用tnsnames.ora进行连接:

and to connect not using the tnsnames.ora:

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

必须预先定义$ host,$ sid.

where the $host, $sid have to be defined beforehand.

这篇关于DBI上的错误ORA-12154->使用Solaris 10中的Oracle Instant Client连接到Oracle数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-21 23:41