Perl 脚本无法从 linux shell 连接到 Oracle,并显示错误和代码
我需要一些帮助来确定从 perl 文件到数据库的连接问题。
当从网络(浏览器到 /file.pl url)运行时,代码可以正常运行和执行。
在 shell 上下文(putty)中,当我运行脚本“perl /file.pl”时,出现此错误:
[date] file.pl: DBI connect('address','username', 'password') failed:
ERROR OCIEnvNlsCreate (check OR ACLE_HOME and NLS settings etc.) at file.pl line 61
第 61 行显示:
$dbh = DBI->connect(A, B, C );
更多详细信息:当另一个用户(可能具有更多权限)运行该文件时,它对他有效(在外壳中)。
#!/usr/bin/perl -w
require 'include.pl';
require 'bencfg.pl';
use lib '/www/modules/'; #rqd
use DBI;
use DBD::Oracle;
print "Content-type: text/html; charset=UTF-8\n\n";
print "Test Run of connection...\n\n<br>";
print "ORA_HOME: '$ENV{ORACLE_HOME}'\n<br>"; #ORA_HOME: '/opt/oracle/10g/'
#connect to DB
$dbh = DBI->connect(A, B C) || die "Database connection not made: $DBI::errstr";
if($dbh){
print "OK\n<br>";
$dbh->disconnect;
}
else{
print "failed: $DBI::errstr\n";
}
我知道 DBI->connect 工作的变量。那不是问题。我相信它的权限,但我不知道如何修复它。
一些附加信息: ORA_HOME: '/opt/oracle/10g'
NLS_SESSION_PARAMETERS
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT MM/DD/YYYY HH24:MI:SS
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
I need some help in determining the problem with my connection from a perl file to a DB.
The code runs and executes fine when it is run from the web (browser to /file.pl url).
In a shell context (putty), when I run the script "perl /file.pl", I get this error:
[date] file.pl: DBI connect('address','username', 'password') failed:
ERROR OCIEnvNlsCreate (check OR ACLE_HOME and NLS settings etc.) at file.pl line 61
Line 61 reads:
$dbh = DBI->connect(A, B, C );
More details: When another user (with presumably more permissions) runs the file, it works for him (in the shell).
#!/usr/bin/perl -w
require 'include.pl';
require 'bencfg.pl';
use lib '/www/modules/'; #rqd
use DBI;
use DBD::Oracle;
print "Content-type: text/html; charset=UTF-8\n\n";
print "Test Run of connection...\n\n<br>";
print "ORA_HOME: '$ENV{ORACLE_HOME}'\n<br>"; #ORA_HOME: '/opt/oracle/10g/'
#connect to DB
$dbh = DBI->connect(A, B C) || die "Database connection not made: $DBI::errstr";
if($dbh){
print "OK\n<br>";
$dbh->disconnect;
}
else{
print "failed: $DBI::errstr\n";
}
I know the variables of DBI->connect work. Thats not the issue. I believe its permissions but I cant tell how to fix it.
Some additional info:
ORA_HOME: '/opt/oracle/10g'
NLS_SESSION_PARAMETERS
PARAMETER VALUE
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT MM/DD/YYYY HH24:MI:SS
NLS_DATE_LANGUAGE AMERICAN
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每次我在连接到 10g 时遇到此问题时,我都必须确保设置了 NLS_LANG env var:
另外,将 ORA_NLS 设置为 nls 文件的路径
Re:
更多详细信息: ... 当另一个用户 ...运行该文件,它对他有用
尝试转储该用户的环境设置,
Every time I've had this issue with connecting to 10g, I had to make sure NLS_LANG env var was set:
Plus, set ORA_NLS to path of nls files
Re:
More details: ... When another user ... runs the file, it works for him
Try dumping that user's env settings,