I'm connecting to two databases at the same time, test and production. I have two sets of DSN connections and connection checks:
                
my $DSN = "Real";                     
my $DSN2 = "Test";
my $connection = new Win32::ODBC($DSN);
my $connection2 = new Win32::ODBC($DSN2);

## Make sure the connection is valid
if ( ! $connection)
{
    die "\n\tCould not open connection to DSN because of [$!]\n";
}

## Make sure the connection is valid
if ( ! $connection2)
{
    die "\n\tCould not open connection2 to DSN2 because of [$!]\n";
}

*****

I can stick this logic in the beginning of the script.

But when I retrieve data and I trap for errors, I find I need two different sets of logic, one for test and one for real.

For instance:

my $SQL = "SELECT CustomerID, CompanyName FROM Customers";

if($connection->Sql($SQL))
{
    print "I could not execute the following statement:\n $SQL\n";
    print "I encountered this error:\n";
    print $connection->Error() . "\n";

    ## Closing the database connection
    $connection->Close();

    ## Exiting the program
    die;
}

while($connection->FetchRow())
{       
    my @dataRow = $connection->Data();
    print $dataRow[0] . " : " . $dataRow[1] . "\n";
}

From what I've read, I need two each of these sections, one for each DSN and connection -- one for the Real DB and one for the Test DB.

The IF and WHILE sections above would belong to the Real DB. While I'm working with the Test DB, I'd need the following:

if($connection2->Sql($SQL))
{
    print "I could not execute the following statement:\n $SQL\n";
    print "I encountered this error:\n";
    print $connection2->Error() . "\n";

    ## Closing the database connection
    $connection2->Close();

    ## Exiting the program
    die;
}

while($connection2->FetchRow())
{       
    my @dataRow = $connection2->Data();
    print $dataRow[0] . " : " . $dataRow[1] . "\n";
}

Does this sound correct? I need to work with both DBs at the same time, and the code's getting a bit sloppy looking. Any suggestions?

-- Craig


        




---
avast! Antivirus: Outbound message clean.
Virus Database (VPS): 0535-1, 08/31/2005
Tested on: 8/31/2005 11:45:10 AM
avast! - copyright (c) 1988-2004 ALWIL Software.
http://www.avast.com



_______________________________________________
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to