private void mitemSynchronize_Click(object sender, System.EventArgs e) { SqlCeReplication replNW = new SqlCeReplication(); try { replNW.ExchangeType = ExchangeType.BiDirectional; replNW.InternetUrl = strURL; replNW.InternetLogin = ""; replNW.InternetPassword = ""; replNW.Publisher = "SNOWDEN"; replNW.PublisherDatabase = "Northwind"; replNW.Publication = "EmployeeOrderInfo"; replNW.PublisherSecurityMode = SecurityType.DBAuthentication; replNW.PublisherLogin = "******"; replNW.PublisherPassword = "******"; replNW.Subscriber = "YaoDurant"; replNW.SubscriberConnectionString = strConnLocal; replNW.Synchronize(); } catch (SqlCeException exSQL) { HandleSQLException(exSQL); } finally { replNW.Dispose(); } }
protected virtual void Dispose(bool disposing) { if (repl != null) { repl.Dispose(); } }
/// <summary> /// Download data for the subscription from the server, and don't return until the download /// finishes. /// </summary> /// <param name="subscription"> /// The subscription for which you want to download data from the server. /// </param> public void Synchronize(Subscription subscription) { Guard.ArgumentNotNull(subscription, "subscription"); if (!Subscriptions.Contains(subscription)) { throw new ArgumentException(Properties.Resources.NoSuchSubscription); } SubscriptionCredentials credentials = subscriptionCredentials.FindCredentials(subscription); SqlCeReplication replication = GetSyncReplication(subscription); if (credentials != null) { credentials.ApplyCredentials(replication); } try { replication.Synchronize(); } finally { replication.Dispose(); ReloadSubscriptions(); } }
private void btnSinkroniziraj_Click(object sender, EventArgs e) { lblPoruka.Text = String.Empty; lblPoruka.ForeColor = SystemColors.ControlText; txtServer.Text = txtServer.Text.Trim(); if (txtServer.Text == String.Empty) { MessageBox.Show("Naziv servera je obavezan."); return; } SqlCeReplication r = new SqlCeReplication(); r.InternetUrl = "http://" + txtServer.Text + "/merge-replication-novapp/sqlcesa35.dll"; r.InternetLogin = String.Empty; r.InternetPassword = String.Empty; r.Publisher = txtServer.Text; r.PublisherDatabase = "NovaPP"; r.Publication = "NovaPP"; r.PublisherSecurityMode = SecurityType.DBAuthentication; r.PublisherLogin = "******"; r.PublisherPassword = "******"; r.SubscriberConnectionString = Program.ConnString; r.Subscriber = "DlanovnikPP"; r.ExchangeType = ExchangeType.BiDirectional; try { if (File.Exists(Program.PathToLocalDB)) { r.ReinitializeSubscription(true); } else { r.AddSubscription(AddOption.CreateDatabase); } r.Synchronize(); lblPoruka.Text = "Sinkronizacija podataka je uspješno provedena."; } catch (Exception ex) { lblPoruka.Text = ex.Message; lblPoruka.ForeColor = Color.Red; } finally { r.Dispose(); } }
/// <summary> /// Adds a new subscription to the database. Call <see cref="BeginSync"/> to /// download the subscription from the server. /// </summary> /// <remarks> /// The subscription information is initially stored in the SubscriptionInfo /// table only in the local database. It will also appear in system tables /// managed by SQL Server Mobile after the first synchronization. Use /// <see cref="BeginSync"/> or <see cref="Synchronize"/> to synchronize /// the data. /// </remarks> /// <param name="sub"></param> /// <exception cref="ArgumentException"> /// A subscription with the same publisher information already exists. /// </exception> public void Add(SubscriptionParameters subscription) { Guard.ArgumentNotNull(subscription, "subscription"); SqlCeReplication replication = new SqlCeReplication(); replication.Publication = subscription.Publication; replication.Publisher = subscription.Publisher; replication.PublisherDatabase = subscription.PublisherDatabase; replication.InternetUrl = subscription.InternetUrl; replication.Subscriber = subscription.Subscriber; replication.HostName = subscription.Filter; Add(replication); replication.Dispose(); }
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(); } } }
private bool SynchronizeSubscription(string subsriptionName, bool reinitializeSubscription, string registryKey, Label label) { bool result = false; Cursor.Current = Cursors.WaitCursor; SqlCeReplication repl = null; try { PerformanceSampling.StartSample(0, "Synchronization time"); repl = new SqlCeReplication(); repl.Publisher = (string)Setting.LocalSetting.GetValue("Server", "WIN2003"); repl.InternetUrl = string.Format("http://{0}/ADA/sqlcesa30.dll", repl.Publisher); this.textBoxStatus.Text += "Synchronizing " + subsriptionName + " data with " + repl.Publisher + " ...\r\n"; this.textBoxStatus.Update(); repl.PublisherDatabase = @"ADA"; repl.PublisherSecurityMode = SecurityType.DBAuthentication; repl.PublisherLogin = @"ada"; repl.PublisherPassword = @"p@ssw0rd"; repl.Publication = subsriptionName; repl.Subscriber = subsriptionName; repl.SubscriberConnectionString = ("Data Source =" + (_databaseFilePath) + (";Password ="******"\"\";")); repl.HostName = _deviceID; if (!File.Exists(_databaseFilePath)) { repl.AddSubscription(AddOption.CreateDatabase); } if (reinitializeSubscription) { repl.ReinitializeSubscription(false); } repl.Synchronize(); PerformanceSampling.StopSample(0); DateTime now = System.DateTime.Now; label.Text = now.ToShortDateString() + " " + now.ToShortTimeString(); label.Update(); this.Setting.LocalSetting.SetValue(registryKey, now); this.textBoxStatus.Text += "Successful!\r\n" + PerformanceSampling.GetSampleDurationText(0) + "\r\n"; result = true; } catch (SqlCeException sqlex) { this.textBoxStatus.Text += "Failed! Error messages:\r\n"; foreach (SqlCeError sqlError in sqlex.Errors) { this.textBoxStatus.Text += sqlError.Message + "\r\n"; } } catch (Exception ex) { this.textBoxStatus.Text += "Failed! Error messages:\r\n" + ex.Message + "\r\n"; } finally { if (repl != null) { repl.Dispose(); } } Cursor.Current = Cursors.Default; return(result); }
internal void CancelSync() { replication.CancelSynchronize(); replication.Dispose(); replication = null; }