当我尝试连接到 Oracle 11g 时,为什么 Perl 的 DBI 会抱怨“失败:错误 OCIEnvNlsCreate”?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2914320/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 02:35:26  来源:igfitidea点击:

Why does Perl's DBI complain about "failed: ERROR OCIEnvNlsCreate" when I try to connect to Oracle 11g?

perloracledbi

提问by John

I am getting the following error connecting to an Oracle 11g database using a simple Perl script:

我使用简单的 Perl 脚本连接到 Oracle 11g 数据库时出现以下错误:

 failed: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var  or PATH (Windows) and or NLS settings, permissions, etc. at

The script is as follows:

脚本如下:

#!/usr/local/bin/perl

use strict;
use DBI;

if ($#ARGV < 3) {
print "Usage: perl testDbAccess.pl dataBaseUser dataBasePassword SID dataBasePort\n";
exit 0;
}
my ($user, $pwd, $sid, $port) = @ARGV;

my $host = `hostname`;
my $dbh;
my $sth;
my $dbname = "dbi:Oracle:HOST=$host;SID=$sid;PORT=$port";

openDbConnection();
closeDbConnection();

sub openDbConnection() {
        $dbh = DBI->connect ($dbname, $user ,$pwd , { RaiseError => 1}) || die "Database connection not made: $DBI::errstr";
}

sub closeDbConnection() {
        #$sth->finish();
        $dbh->disconnect();
}

Anyone seen this problem before?

有人见过这个问题吗?

回答by hobbs

Check your Oracle client configuration (including, as the message says, ORACLE_HOME), check file permissions, etc. It's unlikely that DBI per se has anything to do with the problem, and I know for a fact that DBD::Oracle is compatible with the 11g libraries (at least the 11g InstantClient).

检查您的 Oracle 客户端配置(包括消息所说的 ORACLE_HOME),检查文件权限等。 DBI 本身不太可能与该问题有任何关系,而且我知道 DBD::Oracle 与11g 库(至少是 11g InstantClient)。

回答by Shib

  • Install the perl module DBD::Oracle
  • Add use DBD::Oracle;into your perl script.
  • 安装 perl 模块DBD::Oracle
  • 添加use DBD::Oracle;到您的 perl 脚本中。

This made the problem go away for me.

这让我的问题消失了。

回答by VegaX

Afther upgrade Oracle form 10.2.0.4 to 10.2.0.5 my Perl-CGI not working, the error.log file of Apache was the error:

将 Oracle 表单 10.2.0.4 升级到 10.2.0.5 后,我的 Perl-CGI 不起作用,Apache 的 error.log 文件是错误:

DBI connect('DB','user',...) failed: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var or PATH (Windows) and or NLS settings, permissions, etc. at ... OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var or PATH (Windows) and or NLS settings, permissions, etc.! at ...

DBI connect('DB','user',...) 失败:错误 OCIEnvNlsCreate。在... OCIEnvNlsCreate 检查 ORACLE_HOME (Linux) env var 或 PATH (Windows) 和/或 NLS 设置、权限等。检查 ORACLE_HOME (Linux) env var 或 PATH (Windows) 和/或 NLS 设置、权限等!在 ...

adding the following directive solve the problem:

添加以下指令解决问题:

my $ORACLE_HOME = "/usw/app/oracle/product/10.2";
$ENV{ORACLE_HOME}=$ORACLE_HOME;

回答by Joakim

Sorry for bringing this thread alive again, but I've been trying to solve this issue for weeks. Nowhere did I find that what finally solved it for me.

很抱歉让这个线程再次活跃起来,但我几个星期以来一直在努力解决这个问题。我没有发现最终为我解决的问题。

Environment: RedHat 6.5, Oracle Instant Client 12.1, Apache 2.2

环境:RedHat 6.5、Oracle Instant Client 12.1、Apache 2.2

What solved it for me:Change the permissions of the directory where Oracle Instant Client is installed., which must also be the value of LD_LIBRARY_PATH. The directory wasn't accessible to "other", just owner and group. This command made the whole difference:

为我解决了什么问题:更改安装 Oracle Instant Client 的目录的权限,该权限也必须是 LD_LIBRARY_PATH 的值。“其他”无法访问该目录,只能访问所有者和组。这个命令使整个不同:

# chmod o+rx INSTANTCLIENT-DIRECTORY

I had been trying to create every possible combination of ORACLE_HOME and LD_LIBRARY_PATH. (Even "unsetting" ORACLE_HOME; I found suggestions that would solve the issue, since Instant Client needed only LD_LIBRARY_PATH and !NOT! ORACLE_HOME.) Nothing helped, until ... it hit me to look further in the error message:

我一直在尝试创建 ORACLE_HOME 和 LD_LIBRARY_PATH 的所有可能组合。(甚至“取消设置” ORACLE_HOME;我找到了可以解决问题的建议,因为 Instant Client 只需要 LD_LIBRARY_PATH 和 !NOT!ORACLE_HOME。)没有任何帮助,直到......它让我在错误消息中进一步查看:

    failed: ERROR OCIEnvNlsCreate. Check ORACLE_HOME (Linux) env var
    or PATH (Windows) and or NLS settings, permissions, etc.

permissionsbeing the key word!

权限是关键词!

Hope this helps someone else!

希望这对其他人有帮助!

回答by tprocter

The environment variable used to specify the Oracle libraries may be different from one system to another. On most systems, use LD_LIBRARY_PATH but it may also be LIBPATH (notably on AIX), DYLD_LIBRARY_PATH, or maybe others.

用于指定 Oracle 库的环境变量可能因系统而异。在大多数系统上,使用 LD_LIBRARY_PATH 但它也可能是 LIBPATH(特别是在 AIX 上)、DYLD_LIBRARY_PATH 或其他。

回答by krish___na

I too went through the same issue. In my case ORACLE_HOME environment variable was incorrect.

我也遇到了同样的问题。在我的情况下 ORACLE_HOME 环境变量不正确。

回答by José

Check the #!/usr/bin/perl(first line of your script) is the right perl version you wish to use too !

检查#!/usr/bin/perl(脚本的第一行)是否也是您希望使用的正确 perl 版本!

回答by Spencer

Previous answers don't solve this problem, but they did point me in the right direction: The launched environment was missing the DYLD_LIBRARY_PATHfor Oracle instantclient. You can check by calling: launchctl export

以前的答案没有解决这个问题,但它们确实为我指明了正确的方向:启动的环境缺少DYLD_LIBRARY_PATHOracle 即时客户端。您可以拨打以下电话查询:launchctl export

or

或者

launchctl getenv variable_namein OS X 10.10

launchctl getenv variable_name在 OS X 10.10 中

I compared the output from my .bash_profile and found that the path to instanclient wasn't in launchctl PATHand DYLD_LIBRARY_PATH- Once I added them with the following it worked:

我比较了 .bash_profile 的输出,发现 instanclient 的路径不在launchctl PATH并且DYLD_LIBRARY_PATH- 一旦我使用以下内容添加它们,它就起作用了:

launchctl setenv PATH /path/to/instantclient
launchctl setenv DYLD_LIBRARY_PATH /path/to/instantclient