为什么 Perl 的 DBI 会抱怨“failed: ERROR OCIEnvNlsCreate”?当我尝试连接到 Oracle 11g 时?

发布于 2024-09-03 12:43:44 字数 851 浏览 5 评论 0原文

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

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

脚本如下:

#!/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();
}

有人以前见过这个问题吗?

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

 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(9

另类 2024-09-10 12:43:44

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

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).

烟酉 2024-09-10 12:43:44
  • 安装perl模块 DBD::Oracle
  • use DBD::Oracle; 添加到 Perl 脚本中。

这让我的问题消失了。

  • Install the perl module DBD::Oracle
  • Add use DBD::Oracle; into your perl script.

This made the problem go away for me.

删除会话 2024-09-10 12:43:44

将 Oracle 从 10.2.0.4 升级到 10.2.0.5 后,我的 Perl-CGI 无法正常工作,Apache 的 error.log 文件出现以下错误:

DBI 连接('DB','用户',...)失败:错误 OCIEnvNlsCreate。查看
ORACLE_HOME (Linux) env var 或 PATH (Windows) 和/或 NLS 设置,
权限等...
OCIEnvNlsCreate。检查 ORACLE_HOME (Linux) 环境变量或 PATH (Windows)
和/或 NLS 设置、权限等!在...

添加以下指令解决问题:

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

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:

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 ...

adding the following directive solve the problem:

my $ORACLE_HOME = "/usw/app/oracle/product/10.2";
$ENV{ORACLE_HOME}=$ORACLE_HOME;
浮世清欢 2024-09-10 12:43:44

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

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

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

# chmod o+rx INSTANTCLIENT-DIRECTORY

我一直在尝试创建 ORACLE_HOME 和 LD_LIBRARY_PATH 的所有可能的组合。 (甚至“取消设置”ORACLE_HOME;我找到了可以解决问题的建议,因为即时客户端只需要 LD_LIBRARY_PATH 和!而不是!ORACLE_HOME。)没有任何帮助,直到...
我突然想到要进一步查看错误消息:

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

权限是关键词!

希望这对其他人有帮助!

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

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:

# 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:

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

permissions being the key word!

Hope this helps someone else!

小苏打饼 2024-09-10 12:43:44

CentOS 8 等的 2021 更新:-

如果您使用 systemctl,您的环境或 Apache 设置中的任何内容都无法将环境变量传递给 DBI!

您需要编辑 /usr/lib/systemd/system/httpd.service 文件并在 [Service] 部分后添加适当的行,如下所示:

[Service]
Environment=ORACLE_HOME=/opt/oracle/product/19c/dbhome_1

然后照常重新启动 apache:-

/bin/systemctl restart httpd.service

(如果对您有帮助,请投票:这对于这个老问题,网页是排名第一的谷歌结果,systemctl“安全”已经重生)

2021 Update for CentOS 8 etc:-

If you use systemctl, nothing in your environment or Apache setup can pass environment vars to DBI!

you need to edit the /usr/lib/systemd/system/httpd.service file and add appropriate lines like this after the [Service] section:

[Service]
Environment=ORACLE_HOME=/opt/oracle/product/19c/dbhome_1

Then re-start apache as usual:-

/bin/systemctl restart httpd.service

(Vote this up if it helped you: this web page is the #1 google result for this old problem which systemctl "security" has rebirthed)

雪化雨蝶 2024-09-10 12:43:44

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

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

镜花水月 2024-09-10 12:43:44

以前的答案没有解决这个问题,但它们确实为我指明了正确的方向:启动的环境缺少 Oracle instantclient 的 DYLD_LIBRARY_PATH 。 调用 launchctl export

您可以通过在 OS X 10.10 中

launchctl getenv variable_name 进行检查我比较了 .bash_profile 的输出,发现 instanclient 的路径不在 < code>launchctl PATH 和 DYLD_LIBRARY_PATH - 一旦我使用以下内容添加它们,它就起作用了:

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

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

or

launchctl getenv variable_name in OS X 10.10

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

launchctl setenv PATH /path/to/instantclient
launchctl setenv DYLD_LIBRARY_PATH /path/to/instantclient
听风吹 2024-09-10 12:43:44

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

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.

不念旧人 2024-09-10 12:43:44

我也经历过同样的问题。就我而言,ORACLE_HOME 环境变量不正确。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文