sub getConn { my ($DB,$pwd) = @_; my $count = 0; my $dbhParm; my $USER = 'sa'; my $api = 'Sybase'; while(!$dbhParm) { if (! ($dbhParm = DBI->connect("dbi:$api:${DB}", $USER, $pwd, {PrintError => 0}))) { warn "Can't connect to ${DB} as \"$USER\"\n$DBI::errstr... Retry after 1 seconds\n"; sleep (1); $count++; if ($count > 2) { print "Connection to the database, ${DB} could not be established"; } } last if ($count > 2); # Give up after three tries } return $dbhParm; }