rebelpacket has asked for the wisdom of the Perl Monks concerning the following question:

Greetings! Simple question actually.
I'm writing a perl script that needs uses the Perl DBI. I'm using the Oracle DBD module to connect to (obviously) a oracle database. My connect string looks something like this:

my $dbh = DBI->connect( 'dbi:Oracle:$sid', 'username', 'password') || die "Could Not Make Database Connection";


I get the error that it cannot find the listener "$sid". Thus, it is not interpreting $sid as a variable. Is there a special way that I need to do this with DBI? I've tried {$sid} as well. No luck.
Any ideas?
Thanks,

Replies are listed 'Best First'.
Re: Specifying Variable SID in DBD::Oracle
by impossiblerobot (Deacon) on Feb 28, 2002 at 22:38 UTC
    You are single-quoting dbi:Oracle:$sid so that the variable is not being interpolated. Use double-quotes instead.

    Impossible Robot
Re: Specifying Variable SID in DBD::Oracle
by ajwans (Scribe) on Mar 01, 2002 at 03:40 UTC
    Make sure you set the environment variable ORACLE_HOME first of all. I also set the TWO_TASK environment variable so I don't have to put the SID in the script.
    $ENV{ORACLE_HOME}=/path/to/oracle $ENV{TWO_TASK}=T:IP_ADDRESS:SID $database = DBI->connect ('dbi:Oracle', $user, $pass, {});
    Edit dws add code tags