Perl script cannot connect to Oracle from linux shell with error and code
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/o开发者_StackOverflow社区racle/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
Every time I've had this issue with connecting to 10g, I had to make sure NLS_LANG env var was set:
## for utf8 data
$ENV{NLS_LANG} = 'american_america.al32utf8';
## for ios-8859-1 data
$ENV{NLS_LANG} = 'american_america.we8iso8859p1';
Plus, set ORA_NLS to path of nls files
$ENV{ORA_NLS} = -d "$ENV{ORACLE_HOME}/ocommon/nls/admin/data" ? "$ENV{ORACLE_HOME}/ocommon/nls/admin/data" :
-d "$ENV{ORACLE_HOME}/nls/admin/data" ? "$ENV{ORACLE_HOME}/nls/admin/data" :
-d "$ENV{ORACLE_HOME}/nls/data" ? "$ENV{ORACLE_HOME}/nls/data"
$ENV{ ORA_NLS32 } = $ENV{ORACLE_NLS};
Re: More details: ... When another user ... runs the file, it works for him
Try dumping that user's env settings,
env|grep NLS
精彩评论