The connect should not be nested in the for comprehension. You should put this Try statement before the for.