为什么 Perl 的 DBI 会抱怨“failed: ERROR OCIEnvNlsCreate”?当我尝试连接到 Oracle 11g 时?
我使用简单的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(9)
检查您的 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).
use DBD::Oracle;
添加到 Perl 脚本中。这让我的问题消失了。
use DBD::Oracle;
into your perl script.This made the problem go away for me.
将 Oracle 从 10.2.0.4 升级到 10.2.0.5 后,我的 Perl-CGI 无法正常工作,Apache 的 error.log 文件出现以下错误:
添加以下指令解决问题:
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:
adding the following directive solve the problem:
很抱歉让这个线程再次活跃起来,但几周来我一直在努力解决这个问题。我没有找到最终为我解决的问题。
环境:RedHat 6.5、Oracle Instant Client 12.1、Apache 2.2
为我解决的问题:
更改Oracle Instant Client安装目录的权限,也必须是LD_LIBRARY_PATH的值。 “其他”无法访问该目录,只能访问所有者和组。这个命令使整个不同:
我一直在尝试创建 ORACLE_HOME 和 LD_LIBRARY_PATH 的所有可能的组合。 (甚至“取消设置”ORACLE_HOME;我找到了可以解决问题的建议,因为即时客户端只需要 LD_LIBRARY_PATH 和!而不是!ORACLE_HOME。)没有任何帮助,直到...
我突然想到要进一步查看错误消息:
权限是关键词!
希望这对其他人有帮助!
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:
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:
permissions being the key word!
Hope this helps someone else!
CentOS 8 等的 2021 更新:-
如果您使用 systemctl,您的环境或 Apache 设置中的任何内容都无法将环境变量传递给 DBI!
您需要编辑 /usr/lib/systemd/system/httpd.service 文件并在 [Service] 部分后添加适当的行,如下所示:
然后照常重新启动 apache:-
(如果对您有帮助,请投票:这对于这个老问题,网页是排名第一的谷歌结果,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:
Then re-start apache as usual:-
(Vote this up if it helped you: this web page is the #1 google result for this old problem which systemctl "security" has rebirthed)
检查
#!/usr/bin/perl
(脚本的第一行)是否是您想要使用的正确的 perl 版本!Check the
#!/usr/bin/perl
(first line of your script) is the right perl version you wish to use too !以前的答案没有解决这个问题,但它们确实为我指明了正确的方向:启动的环境缺少 Oracle instantclient 的 DYLD_LIBRARY_PATH 。 调用
launchctl export
或
您可以通过在 OS X 10.10 中
launchctl getenv variable_name
进行检查我比较了 .bash_profile 的输出,发现 instanclient 的路径不在 < code>launchctl PATH 和DYLD_LIBRARY_PATH
- 一旦我使用以下内容添加它们,它就起作用了: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.10I compared the output from my .bash_profile and found that the path to instanclient wasn't in
launchctl PATH
andDYLD_LIBRARY_PATH
- Once I added them with the following it worked:用于指定 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.
我也经历过同样的问题。就我而言,ORACLE_HOME 环境变量不正确。
I too went through the same issue. In my case ORACLE_HOME environment variable was incorrect.