Wrap the connect in an eval{} and test for success.
This is just one way to do it of course. You could also connect with RaiseError => 0, and reset it to 1 on a successful connection. If you're new to Perl and/or DBI, two excellent investments you should make are the "Perl CD Bookshelf" and "Programming the Perl DBI". You will find them invaluable, and they will save you a lot of time. Jared #!/usr/bin/perl use warnings; use DBI; use strict; my $db = 'ts01'; my $dbh=undef; my @users = ( [qw{scott notiger}], [qw{scott tiger}] ); foreach my $user ( @users ) { print "user: $user->[0]\n"; print "pwd: $user->[1]\n"; eval { $dbh = DBI->connect( 'dbi:Oracle:' . $db, $user->[0], $user->[1], { RaiseError => 1, AutoCommit => 0, ora_session_mode => 0 } ); }; if ($@) { warn "Connect to $db failed \n" ; warn "continuing with the next user\n\n"; next; } my $MySql="select \* from dual"; my $sth = $dbh->prepare($MySql); $sth->execute; my $href = $sth->fetchrow_hashref; print "DUMMY: $href->{DUMMY}\n"; $sth->finish; } $dbh->disconnect; On Thursday 07 February 2002 09:33, Khamneian, Mahtaj wrote: > You're right. I have been working with shell scripts, using sqlplus, too > long. What I need to do is to continue (rather than die) the script, > attempting to connect with another userid/passwd, when a connection fails > and I get "Segmentation Fault" after the first successful login. Now, I > have a suspicion that there is a time conflict between disconnect and the > next connect. Maybe I should make the script wait a little after each > disconnect. Any suggestions/comments? > > Thanks a lot for the pointer, > > -Mahtaj > > > -----Original Message----- > > From: Jared Still [mailto:[EMAIL PROTECTED]] > > Sent: Thursday, February 07, 2002 11:07 AM > > To: Khamneian, Mahtaj; [EMAIL PROTECTED] > > Subject: Re: Perl DBI->connect > > > > > > > > Are you sure you're using DBI? > > > > If the password is incorrect, the connection should fail. > > > > The behavior you describe is typical of Sqlplus. > > > > Assuming that you have a scott/tiger account, the following script > > should simply fail and report an error: ( change the value of > > $db first ) > > > > #!/usr/bin/perl > > > > use warnings; > > use DBI; > > use strict; > > > > my ($db, $username, $password) = qw{ts01 scott notiger}; > > > > my $dbh = DBI->connect( > > 'dbi:Oracle:' . $db, > > $username, $password, > > { RaiseError => 1, AutoCommit => 0, ora_session_mode => 0 } > > ); > > > > die "Connect to $db failed \n" unless $dbh; > > my $MySql="select \* from dual"; > > my $sth = $dbh->prepare($MySql); > > $sth->execute; > > > > my $href = $sth->fetchrow_hashref; > > print "DUMMY: $href->{DUMMY}\n"; > > > > $sth->finish; > > $dbh->disconnect; > > > > Jared > > > > On Thursday 07 February 2002 08:06, Khamneian, Mahtaj wrote: > > > I have written a perl DBI script to check passwords of some > > > > 1500 users on > > > > > an oracle database. I have set up a loop to go through a > > > > list containing > > > > > userid:password of each user on a separate line. I use > > > > DBI->connect to > > > > > connect to the instance using the userid/password from the list. If > > > connection is successful, I record the info in a file and > > > > disconnect from > > > > > the db and check the next userid/passwd with another > > > > connect. The problem > > > > > is when the wrong password is supplied, oracle prompts for > > > > correct userid. > > > > > What oracle state is this(I cannot disconnect because I'm > > > > not connected)? > > > > > And how can I handle it in perl? Is there a more efficient > > > > way to do this > > > > > in perl than what I have explained above? > > > > > > Thanks, > > > > > > ------------------------------------- > > > Mahtaj Khamneian > > > University of Missouri - ASP Phone : (573) 884-2281 > > > 1805 East Walnut Fax : (573) 884-3070 > > > Columbia, MO 65201-6425 [EMAIL PROTECTED]