private void DoWork() { try { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); DropTable(connection); CreateTable(connection); foreach (MapFeature mapFeature in _mapFeatures) { try { SqlCommand command = MsSqlCommandCreator.CreateCommand(mapFeature, _geographyMode, _srid, _tableName, _placemarkColumnName, connection); command.ExecuteNonQuery(); } catch (Exception ex) { _worker.ReportProgress(0, ex.Message); } _worker.ReportProgress(0, String.Format("Uploading Placemark # {0}", mapFeature.Id)); } _worker.ReportProgress(0, "Done!"); } } catch (Exception ex) { _worker.ReportProgress(0, ex.Message + "\r\n\r\n" + ex); _worker.CancelAsync(); MessageBox.Show("The process failed with the following error: \r\n\r\n " + ex.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { WriteOutLog(); } }
private void DoWork() { var failed = false; try { using (var connection = new SqlConnection(_connectionString)) { connection.Open(); DropTable(connection); CreateTable(connection); foreach (MapFeature mapFeature in _mapFeatures) { try { SqlCommand command = MsSqlCommandCreator.CreateCommand(mapFeature, _geographyMode, _srid, _tableName, _placemarkColumnName, connection); command.ExecuteNonQuery(); } catch (Exception ex) { _worker.ReportProgress(0, ex.Message); } _worker.ReportProgress(0, String.Format("Uploading Placemark # {0}", mapFeature.Id)); } _worker.ReportProgress(0, "Done!"); } if (failed) { throw new AggregateException("Import failed"); } } catch (Exception ex) { _worker.ReportProgress(0, ex.Message); _worker.CancelAsync(); } }