Reputation: 63
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?
Upvotes: 5
Views: 24055
Reputation:
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)
Upvotes: 1
Reputation: 722
I too went through the same issue. In my case ORACLE_HOME environment variable was incorrect.
Upvotes: 0
Reputation: 26
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.
Upvotes: 0
Reputation: 121
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!
Upvotes: 2
Reputation: 1
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
Upvotes: 0
Reputation: 1
Check the #!/usr/bin/perl
(first line of your script) is the right perl version you wish to use too !
Upvotes: 0
Reputation: 21
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;
Upvotes: 2
Reputation: 31
use DBD::Oracle;
into your perl script.This made the problem go away for me.
Upvotes: 3
Reputation: 240294
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).
Upvotes: 7