Index: trunk/ippScripts/scripts/magic_destreak_cleanup.pl
===================================================================
--- trunk/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 27603)
+++ trunk/ippScripts/scripts/magic_destreak_cleanup.pl	(revision 27604)
@@ -118,7 +118,17 @@
 
 my $num_components = 0;
+my @components;
+# save the data, so we can disconnect from the database
+# deleting can take awhile
 while (my $comp = $stmt2->fetchrow_hashref()) {
+        push @components, $comp;
         $num_components++;
-
+}
+
+$stmt2->finish();
+$dbh->disconnect() or warn $dbh->errstr;
+
+my $dynamicMasks;               # Use dynamic masks?
+foreach my $comp (@components) {
         my $component = $comp->{component};
         my $backup_path_base = $comp->{backup_path_base};
@@ -129,6 +139,5 @@
         if ($stage eq "chip") {
             # Check to see if we're using dynamic masks
-            my $dynamicMasks;               # Use dynamic masks?
-            {
+            if (!defined $dynamicMasks) {
                 # Get the PSASTRO recipe
                 my $command = "$ppConfigDump -camera $camera -recipe PSASTRO $recipe_psastro -dump-recipe PSASTRO -";
@@ -228,4 +237,6 @@
 }
 
+$dbh = DBI->connect($dsn, $dbuser, $dbpassword) or die "Cannot connect to mysql server\n";
+
 if (!$no_update and ($num_components > 0)) {
     my $result = $dbh->do("DELETE FROM magicDSFile WHERE magic_ds_id = ?", undef, $magic_ds_id);
