> > Hi, > > I have a problem that my program crashes, since I added a > second connect in a loop. I know that the code isn't good yet > (I should use placeholders), but it shouldn't crash anyway?
No, it shouldn't -- but I can't see the crash message -- what does the dialog box say?. Please update to DBD::ODBC 1.01 as there were some problems in prior versions with memory overwrites. If you can, send a small sample with create tables, etc, which reproduces this. For example script1 would have create table on the DB2 side and insert data, script2 would have create tables on the MSSQL side and script three would be a small part of what you are trying to do in the crashing script. The idea is to cut it down to the smallest possible, reproducable issue (the easier it is for me to look at and run, the faster I can get to it :) Regards, Jeff > The trace(2) is attached, and this is the main part of the code: > > > $db2dbh = DBI->connect("dbi:ODBC:DB2I21", "tefide", "genf23", > { RaiseError => 0, PrintError => 1, AutoCommit => 1} ) or do > {print LOG "!!!!!!!!!!!!!!!!!!!!!!!!!!$now $DBI::errstr\n" ; > $seconds=300 ; next MAINLOOP}; > > $msdbh = DBI->connect("dbi:ODBC:BTETRANSFER", "LOtest", > "LOtest", { RaiseError => 0, PrintError => 1, AutoCommit => 1 > } ) or do {print LOG "!!!!!!!!!!!!!!!!!!!!!!!!!!$now > $DBI::errstr\n" ; $seconds=300 ; next MAINLOOP}; > > $db2sth = $db2dbh->prepare("SELECT * FROM db2bt0xd.bt02th8"); > if ($db2sth->execute) { > while ( @row = $db2sth->fetchrow_array ) { > > ($alfdnr,$anr,$lsdat,$bestnr,$lnr,$kurzname,$oe,$notiz,$aname) = @row; > # Wenn Eintrag bei Notiz, Anforderer > überschreiben mit Notiz > $dupe=0; > $keepnotiz=$notiz; > if ($notiz =~ /\S/) { > $anforderer=$notiz; > } > else { > $anforderer="$oe $aname"; > } > # Insert into MSSQL > # Datum in passendes Format wandeln > @datum= split /-/ ,$lsdat; > $lsdat="$datum[2]."."$datum[1]."."$datum[0]"; > # timestamp in Unix-History > $timestamp=time(); > # Kürzen auf 20 Zeichen > $anforderer=substr($anforderer, 0, 20); > > # Prüfung ob Barcode bereits in MSSQL > $mssth = $msdbh->prepare("SELECT Barcode FROM > BTEDATEN"); > $mssth->execute; > while (@barcodes=$msdbh->fetchrow_array) { > ($barcode) = @barcodes; > if ($barcode eq $alfdnr) { > $dupe=1; > } > } > if ($dupe==1) { > $mssth = $msdbh->prepare("UPDATE > BTEDATEN SET Firma='$kurzname', LSNR='$anr', LSDAT='$lsdat', > ANABT='$anforderer', AKNR='$bestnr', BTENOTIZ='$keepnotiz' > WHERE Barcode='$alfdnr'"); > print LOG "Doppelter Barcode: $alfdnr wird > updated!\n"; > if ($mssth->execute) { > push @todelete, $alfdnr; > } > } > else { > $mssth = $msdbh->prepare("INSERT INTO > BTEDATEN > (Barcode,Firma,LSNR,LSDAT,ANABT,AKNR,TKNR,VONABT,BESTELLNR,SON > STIGES,TIMESTA > MP,BTENOTIZ) VALUES ('$alfdnr', '$kurzname', '$anr', > '$lsdat', '$anforderer', > '$bestnr','','','','','$timestamp','$keepnotiz')") ; > print LOG "Unique Barcode: $alfdnr wird > inserted\n"; > # geschriebene Daten merken zum Löschen > if ($mssth->execute) { > push @todelete,$alfdnr; > } > } > } > $c_todelete=@todelete; > print LOG "###################### $c_todelete Entries > to delete from > BTE: @todelete\n"; > # Daten aus DB2 löschen > foreach $raus (@todelete) { > $db2sth = $db2dbh->prepare("DELETE FROM > db2bt0xd.bt02th8 WHERE A_LFDNR=$raus"); > $db2sth->execute; > } > } > > note: background of the first $msdbh select is that I want to > prevent inserting rows where $alfdnr already exists. I tried > a "INSERT INTO ... WHERE IS NOT (SELECT Barcode FROM > BTEDATEN)..." but it seems i may not combine a INSERT with a > WHERE... DBI is 1.30 ODBC is 0.43 ActiveState Perl 5.6 > > > regards, Lars > >