DBI reconnection does not work with lexical variable in Perl 5.24.0

When I switched perl environment from 5.16.0 to 5.24.0, I got strange behavior that I can not understand. This code

use DBI;

my $conn   = 'dbi:ODBC:sqlserver_xxxx';  
my $userid = 'dw_select';  
my $passwd = 'xxxx';

for ( 1 .. 100 ) {
    warn "start try $_";
    my $dbh = DBI->connect($conn, $userid, $passwd, { RaiseError => 1 } );
    warn "end try $_";  
}

working fine on 5.16.0, but when switching to 5.24.0 I got the following result:

start try 1 at test_con.pl line 9.
end try 1 at test_con.pl line 11.
start try 2 at test_con.pl line 9.
end try 2 at test_con.pl line 11.
start try 3 at test_con.pl line 9.
DBI connect('sqlserver_xxxx','dw_select',...) failed: 
 Unable to fetch information about the error at test_con.pl line 10.

with this modification, it starts again without errors:

use DBI;

my $conn   = 'dbi:ODBC:sqlserver_xxxx';  
my $userid = 'dw_select';  
my $passwd = 'xxxx';

my $dbh;    
for ( 1 .. 100 ) {
    warn "start try $_";
    $dbh = DBI->connect($conn, $userid, $passwd, { RaiseError => 1 } );
    warn "end try $_";  
}

Do any of you have an explanation?

+6
source share
1 answer

Thanks for the helpful tips! On perl 5.16.0, I used DBI 1.631 and perl 5.24.0 DBI 1.636. I did not consider different versions of DBI in both environments. The hint for using disconnect also worked, but I'm still surprised at the different behavior of the two versions of DBI.

0
source

Source: https://habr.com/ru/post/1016163/


All Articles