private void SyncCompletedCallback(IAsyncResult ar) { try { SqlCeReplication repl = (SqlCeReplication)ar.AsyncState; repl.EndSynchronize(ar); repl.SaveProperties(); string result = "Successfully completed sync" + Environment.NewLine; result += string.Format("Number of changes downloaded: {0}{1}", repl.PublisherChanges.ToString(), Environment.NewLine); result += string.Format("Number of changes uploaded: {0}{1}", repl.SubscriberChanges.ToString(), Environment.NewLine); result += string.Format("Number of conflicts at Publisher: {0}{1}", repl.PublisherConflicts.ToString(), Environment.NewLine); #if V40 SyncArgs4 args = new SyncArgs4(result, null); #else SyncArgs args = new SyncArgs(result, null); #endif Completed(this, args); } catch (SqlCeException e) { #if V40 SyncArgs4 args = new SyncArgs4("Errors occured during sync", e); #else SyncArgs args = new SyncArgs("Errors occured during sync", e); #endif Completed(this, args); } }
public SqlCeReplicationHelper(string connectionString, string url, string publisher, string publicationDatabase, string publication, string subscriber, string hostName, bool useNT, string internetUsername, string internetPassword, string publisherUsername, string publisherPassword, bool isNew, ReinitializeOption reinitialize) { this.repl = new SqlCeReplication(); repl.SubscriberConnectionString = connectionString; _isNew = isNew; _reinitialize = reinitialize; if (isNew) { repl.AddSubscription(AddOption.ExistingDatabase); } if (useNT) { repl.PublisherSecurityMode = SecurityType.NTAuthentication; } else { repl.PublisherSecurityMode = SecurityType.DBAuthentication; } repl.Publisher = publisher; repl.PublisherLogin = publisherUsername; repl.PublisherPassword = publisherPassword; repl.PublisherDatabase = publicationDatabase; repl.Publication = publication; repl.InternetUrl = url; repl.InternetLogin = internetUsername; repl.InternetPassword = internetPassword; repl.Subscriber = subscriber; repl.HostName = hostName; repl.SaveProperties(); }
private void SyncCompletedCallback(IAsyncResult ar) { SqlCeReplication repl = (SqlCeReplication)ar.AsyncState; try { repl.EndSynchronize(ar); repl.SaveProperties(); var result = "Successfully completed sync" + Environment.NewLine; result += string.Format("Number of changes downloaded: {0}{1}", repl.PublisherChanges.ToString(), Environment.NewLine); result += string.Format("Number of changes uploaded: {0}{1}", repl.SubscriberChanges.ToString(), Environment.NewLine); result += string.Format("Number of conflicts at Publisher: {0}{1}", repl.PublisherConflicts.ToString(), Environment.NewLine); var args = new SyncArgs(result, null, 100, SyncStatus.SyncComplete, null); Completed?.Invoke(this, args); InsertSyncLog(_connection, _hostName, _additionalId, "Success", _additionalInfo); } catch (SqlCeException e) { InsertSyncLog(_connection, _hostName, _additionalId, "Error", _additionalInfo + Environment.NewLine + ShowErrors(e)); SyncArgs args; if (e.NativeError == 29006) { args = new SyncArgs("Publication may have expired, or the snapshot is invalid", new PublicationMayHaveExpiredException("Publication may have expired, or the snapshot is invalid", e), 100, SyncStatus.SyncFailed, null); } else { args = new SyncArgs("Errors occured during sync", e, 100, SyncStatus.SyncFailed, null); } Completed?.Invoke(this, args); } finally { if (repl != null) { repl.Dispose(); } if (_connection != null) { _connection.Close(); _connection.Dispose(); } } }