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

Hi! I am using this rough code below to dump some data into a MS Access db and after executing successfully a few times, half way through the records it gives me an "Can't execute SQL statement. Perl says Bad file descriptor, DBI says" error. Any info would you be appreciated. Thanks.
my $dbh = CreateObject OLE "ADODB.Connection" or die "Can't create con +nection to DataBase: $!" unless $dbh; $dbh->Open("Driver={Microsoft Access Driver (*.mdb)};DBQ=db/1.mdb"); my $rs = CreateObject OLE "ADODB.Recordset" or die "can not create rec +ordset"; my $sql = "INSERT INTO classes (subject,classnumber,description) VALUE +S ('$classSubject','$classNumber','$classDescription')"; $rs = $dbh->Execute( $sql ) or die print ( "Can't execute SQL statemen +t. Perl says $!, DBI says ",$dbh::errstr,"\n"); $dbh->Close();
  • Comment on Bad file descriptor error.... No idea what that is ... please help :-D
  • Download Code

Replies are listed 'Best First'.
Re: Bad file descriptor error.... No idea what that is ... please help :-D
by poj (Abbot) on Dec 28, 2002 at 13:29 UTC
    Add these print statements before the ->Execute to see which record it is failing on ;
    print "Subject : $classSubject\n"; print "Number : $classNumber\n"; print "Description : $classDescription\n";
    It is probably something in the description
    poj
      Thanks! That fixed it :-D. Take care.
Re: Bad file descriptor error.... No idea what that is ... please help :-D
by chromatic (Archbishop) on Dec 28, 2002 at 23:07 UTC

    DBI shouldn't be setting $! (and, to my knowledge, doesn't), so that's a meaningless error message. Look in perlvar to see what sets $! and why you can't rely on it in this situation.

      It is usually better to use $DBI::err and $DBI::errstr after a failed connect attempt. (I don't think you can use the methods because there's not an object to reference.)