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

When attempting connection to two databases, if the first succeeds and the second fails, the program hangs, prints "Ok\nUhoh\nDone\n" and never exits.

If I remove the $no_raise_error option, the failed connection prints 'ORA-01017: invalid username/password' message and seg faults.

When the first fails and the second succeeds, prints "Uhoh\nOk\nDone\n" and exits normally.

Anyone else see this? Should I eval wrap the connects? Use a different module?

#!/usr/bin/perl use strict; use DBIx::Simple; my $no_raise_error = { RaiseError => 0, }; my @valid_keys = ( "dbi:Oracle:this_db", "valid-username", 'valid-password', ); my @bogus_keys = ( "dbi:Oracle:that_db", "bogus-username", 'bogus-password', ); my $db = do_connect(\@valid_keys); ($db) and print "Ok\n"; my $db = do_connect(\@bogus_keys, $no_raise_error); ($db) and print "Ok\n"; print "Done\n"; sub do_connect { my $keys = shift; my $opts = shift; my $db = DBIx::Simple->connect(@$keys, $opts) or do { printf "Uhoh\n"; return; }; return $db; }

Replies are listed 'Best First'.
Re: DBIx::Simple hangs
by Khen1950fx (Canon) on Dec 13, 2011 at 22:04 UTC
    Looking at it from a different angle, I would test to ensure that you can actually use DBIx::Simple, that you can connect, and that you can disconnect. I don't have Oracle, so I used DBD::SQLite in this example test. Once you've done this successfully, then you can add tests for users and passwords.
    !/usr/bin/perl -slw use strict; use Test::More; BEGIN { eval { require DBD::SQLite; 1 } or plan skip_all => 'DBD::SQLite required'; plan tests => 3; use_ok('DBIx::Simple'); } ok(my $db = DBIx::Simple->connect( 'dbi:SQLite:dbname=:memory' ) or die DBIx::Simple->error); if (not defined $db) { print "Not Ok: ", $DBI::errstr; } else { print "Ok!"; } ok($db->disconnect); print "Done";
      Thanks for the reply. I've used DBIx::Simple for a couple of years, I'd hate to have to ditch it. I don't often need or use multiple connections, and don't often fail connecting, so this is the first time I've encountered it.

      More info: when I replace DBIx::Simple with plain ole DBI, program doesn't hang when first connection is successful and second connection fails. It exits normally.