RE: Problem with connecting to an Oracle database using Perl

From: Graeme St. Clair (Graeme.St.Clair_at_hds.com)
Date: 01/19/05


To: "'Hardy Merrill'" <HMerrill@dhcr.state.ny.us>, dbi-users@perl.org, charles.lawrence@swifttel.net
Date: Wed, 19 Jan 2005 10:53:33 -0800

Her's a snippet that works.

BEGIN {
  if (($^O eq 'MSWin32') or ($^O =~ /cygwin/i)) {
# $ENV{ORACLE_HOME} = q{C:/Oracle/Ora81}; # But Oracle::DBD will find it
from the Windows registry
  } else {
    $ENV{ORACLE_HOME} = q{/solarisdirectory/app/oracle/product/8.1.7};
  }
# Following string is also visible inside C:/Oracle/Ora81
  $host = q{SOMETHING.COMPANY.COM};
  $uid = q{someuid};
  $pw = q{somepw};

Rgds, GStC.

-----Original Message-----
From: Hardy Merrill [mailto:HMerrill@dhcr.state.ny.us]
Sent: Wednesday, January 19, 2005 7:55 AM
To: Hardy Merrill; dbi-users@perl.org; charles.lawrence@swifttel.net
Subject: Re: Problem with connecting to an Oracle database using Perl

It's probably worth pointing out here that the use of the BEGIN block
*IS* described in the DBD::Oracle perldocs - as the perldocs are included
when you install any module, after you install DBD::Oracle you can do

   perldoc DBD::Oracle

to read the excellent perldocs. Look for the paragraphs titled "Oracle
Environment Variables" and "Connection Examples Using DBD::Oracle".

Hardy

>>> "Hardy Merrill" <HMerrill@dhcr.state.ny.us> 01/19/05 7:46 AM >>>
Hi Charles,

Try setting your environment variables in a BEGIN block, like this:

#!/usr/bin/perl -w
use strict;
BEGIN {
  $ENV{'NLS_LANG} = 'american';
  $ENV{ORACLE_HOME} = 'D:\Oracle\ora92'; }

### the rest of your code goes here ###

I haven't done Perl/DBI/Oracle in quite a while, but that's what I remember
doing. I think that must be spelled out either in the DBI perldocs or the
DBD::Oracle perldocs - to use a BEGIN block to set environment variables
that is ;-)

Hardy Merrill

>>> "Charles Lawrence" <charles.lawrence@swifttel.net> 01/18/05 2:54
PM
>>>
Gentlemen:

 

I have struggled with this problem for a while now with no success at
finding the answer, so I am asking for help from anyone who might know the
solution.

 

I am using Windows XP, ActiveState Perl 5.8.4, Oracle 9.2.0.1.0 client and
server, DBI (1.45) and DBD-Oracle (1.16) installed as ppm packages from
ftp.esoftmatic.com/outgoing/DBI/5.8.4/

 

I do not have a problem connecting to the remote database using the Oracle
Enterprise Manager program from my PC. However, I am getting the following
error when I try to connect to the database from perl:

 

DBI connect('host=10.1.10.61;sid=ssdb','system',...) failed: ERROR
OCIInitialize. Check ORACLE_HOME and NLS settings etc. at
D:\PerlScripts\ora1.

pl line 17

Unable to connect to database: ERROR OCIInitialize. Check ORACLE_HOME and
NLS settings etc.

 

My perl script is:

 

#!/usr/bin/perl

 

use strict;

use DBI;

use DBD::Oracle qw(:ora_session_modes); # ORA_SYSDBA & ORA_SYSOPER constants

 

my ($dsn,$usr,$pwd);

my ($dbh);

 

$ENV{NLS_LANG} = 'american';

$ENV{ORACLE_HOME} = 'D:\Oracle\ora92';

 

# connect to remote Oracle DB

$dsn='DBI:Oracle:host=10.1.10.61;sid=ssdb';

$usr='system';

$pwd='manager';

$dbh = DBI->connect($dsn,$usr,$pwd) || die "Unable to connect to
database: $DBI::errstr\n";

 

I have used NLS_LANG settings of 'american_america.we8iso8859p1' and
'american_america.utf8' to no avail. I know the ORACLE_HOME to be correct.
I cannot figure out why I am getting the OCIInitialize error.
Any help will be greatly appreciated. Thanks in advance.

 

Charles Lawrence

charles@swifttel.net

 



Relevant Pages

  • Re: Slow connection to Oracle 9i
    ... If your server is memory and/or CPU ... I just tested it on two oracle instances on identical ... Connecting to one with MTS took 0.059 seconds, ... Other delays could be in finding the database and authenticating the ...
    (perl.dbi.users)
  • Re: pooled connection using tclhttpd
    ... >> I am using TCLHTTPD as the web server for hosting my applications. ... >> connecting with the oracle database. ... I doubt that oratcl supports async communication with oracle ...
    (comp.lang.tcl)
  • Re: Date / Time a table changed
    ... We are connecting to an Oracle 9i Database, is it possible to query a ...
    (comp.databases.oracle.misc)
  • Re: Oracle RAC connection
    ... Connecting to rac is the same as connecting to any normal oracle database. ... With the tnsnames.ora file for a rac database, you can specify if the alias is to connect to specific node or use the service and allow for the listener to connect you to a random node. ...
    (perl.dbi.users)
  • Re: Problem with connecting to an Oracle database using Perl
    ... *IS* described in the DBD::Oracle perldocs - as the perldocs are ... Look for the paragraphs titled "Oracle ... I do not have a problem connecting to the remote database using the ... Check ORACLE_HOME and NLS settings etc. at ...
    (perl.dbi.users)