private void ResolvePrimaryKeyConflicts(IDataLoadEventListener job) { using (var con = (SqlConnection)_dbInfo.Server.GetConnection()) { con.Open(); PrimaryKeyCollisionResolver resolver = new PrimaryKeyCollisionResolver(TargetTable); SqlCommand cmdAreTherePrimaryKeyCollisions = new SqlCommand(resolver.GenerateCollisionDetectionSQL(), con); cmdAreTherePrimaryKeyCollisions.CommandTimeout = 5000; //if there are no primary key collisions if (cmdAreTherePrimaryKeyCollisions.ExecuteScalar().ToString().Equals("0")) { job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Information, "No primary key collisions detected")); return; } //there are primary key collisions so resolve them job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Warning, "Primary key collisions detected")); SqlCommand cmdResolve = new SqlCommand(resolver.GenerateSQL(), con); cmdResolve.CommandTimeout = 5000; int affectedRows = cmdResolve.ExecuteNonQuery(); job.OnNotify(this, new NotifyEventArgs(ProgressEventType.Warning, "Primary key collisions resolved by deleting " + affectedRows + " rows")); con.Close(); } }
private void btnSelectToClipboard_Click(object sender, EventArgs e) { try { //this is used only to generate the SQL preview of how to resolve primary key collisions so no username/password is required - hence the null,null PrimaryKeyCollisionResolver resolver = new PrimaryKeyCollisionResolver(_table); if (sender == btnCopyPreview) { System.Windows.Forms.Clipboard.SetText(resolver.GeneratePreviewSQL()); } if (sender == btnCopyDetection) { System.Windows.Forms.Clipboard.SetText(resolver.GenerateCollisionDetectionSQL()); } } catch (Exception exception) { ExceptionViewer.Show(exception); } }