Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Multiple DB Connection Problem

by slg_saravanan (Initiate)
on May 31, 2007 at 05:30 UTC ( #618398=perlquestion: print w/ replies, xml ) Need Help??
slg_saravanan has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

When I try to connect more than one Database through my Perl code.It is giving the following error :

Software error: Can't connect to data source "dbi:Oracle:host=;sid=dev;","queryeditor","editor", no database driver specified and DBI_DSN env var not set at /usr/local/apache/cgi-bin/saravanan/queryeditor_dev/dbnameselection.cgi line 47

Following is the part of script :

$ENV{ORACLE_HOME}="/home/oracle/product/10.2.0/db_1"; our $conn1 = DBI->connect("dbi:Oracle:host=;sid=dev;","queryed +itor","editor"); die($DBI::errstr) unless $conn1; my $connection_detail = "select DBDESCRIPTION from qe_dbnamelist where + DBNAME='$dbname'"; my $connection_records = $conn1->prepare($connection_detail) or die("E +rror on preparing the sql statement \n"); $connection_records->execute() or die("Error on getting the data from +QE_GROUP \n"); print "Query String Part"; @connection_resultset= $connection_records->fetchrow_array; $dbconnectionstring = $connection_resultset[0]; print $dbconnectionstring; our $conn2 = DBI->connect($dbconnectionstring); die($DBI::errstr) unless $conn2; print "$dbname Database Successfully Connected !!!";

What actually I am trying to do is, I am fetching ORacle DB connection string (for Ex : "dbi:Oracle:host=;sid=dev;","queryeditor","editor") from one table and I am creating one more different DB connection using that DB connection string. So..during that time I am getting this error.

What could be the problem ? Is that the problem coz of am opening the same connection again ..?

Thanks a ton in Advance !

Warm Regards,

Comment on Multiple DB Connection Problem
Download Code
Re: Multiple DB Connection Problem
by snoopy (Deacon) on May 31, 2007 at 06:43 UTC
    I think its the connection string. The following gives the same error:
    #!/usr/bin/perl use warnings; use strict; use DBI; my $dbconnectionstring = q{"dbi:Oracle:host=;sid=dev;","querye +ditor","editor"}; our $conn2 = DBI->connect($dbconnectionstring); die($DBI::errstr) unless $conn2;
    You need to parse your connection string to extract dsn, user and password and pass then as individual arguments to DBI's connect method:
    use Text::CSV_XS; my $csv = Text::CSV_XS->new({ sep_char => ",", quote_char => '"', }); $csv->parse($dbconnectionstring); my ($dsn,$user,$pass) = $csv->fields(); our $conn2 = DBI->connect($dsn, $user, $pass); die($DBI::errstr) unless $conn2;
      Snoopy..Thanks for the suggestion.

      Is there any other way to do this multiple DB connection without using "use Text::CSV_XS;" module ?
        You could split $dbconnectionstring on commas or if it were me, I would store the information in 3 different columns.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://618398]
Approved by varian
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (5)
As of 2014-09-21 07:10 GMT
Find Nodes?
    Voting Booth?

    How do you remember the number of days in each month?

    Results (167 votes), past polls