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) #endif { this.repl = new SqlCeReplication(); repl.SubscriberConnectionString = connectionString; 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; }
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) #endif { this.repl = new SqlCeReplication(); repl.SubscriberConnectionString = connectionString; 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; }
private void mitemCreateSubscription_Click(object sender, 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.AddSubscription(AddOption.CreateDatabase); } catch (SqlCeException exSQL) { HandleSQLException(exSQL); } finally { replNW.Dispose(); } }
private SqlCeReplication GetSyncReplication(Subscription subscription) { SqlCeReplication replication = new SqlCeReplication(); replication.ConnectionManager = true; replication.SubscriberConnectionString = refDatabase.ConnectionString; replication.Publication = subscription.Publication; replication.Publisher = subscription.Publisher; replication.PublisherDatabase = subscription.PublisherDatabase; replication.Subscriber = subscription.Subscriber ?? String.Empty; replication.InternetUrl = subscription.InternetUrl ?? String.Empty; replication.HostName = subscription.Filter ?? String.Empty; // // Simply setting some of these values, even if we're not changing the // value, causes other values in the same group to become required. As // a result, we have to make sure we don't set null, etc. // replication.CompressionLevel = subscription.CompressionLevel; if (subscription.Distributor != null) { replication.Distributor = subscription.Distributor; } if (subscription.DistributorAddress != null) { replication.DistributorAddress = subscription.DistributorAddress; } if (replication.DistributorNetwork != subscription.DistributorNetwork) { replication.DistributorNetwork = subscription.DistributorNetwork; } replication.ExchangeType = subscription.ExchangeType; if (subscription.InternetProxyServer != null) { replication.InternetProxyServer = subscription.InternetProxyServer; } replication.LoginTimeout = subscription.LoginTimeout; if (subscription.ProfileName != null) { replication.ProfileName = subscription.ProfileName; } if (subscription.PublisherAddress != null) { replication.PublisherAddress = subscription.PublisherAddress; } replication.PublisherNetwork = subscription.PublisherNetwork; replication.QueryTimeout = subscription.QueryTimeout; replication.SnapshotTransferType = (SnapshotTransferType)subscription.SnapshotTransferType; replication.Validate = subscription.Validate; if (!subscription.HasBeenSynchronized) { replication.AddSubscription(AddOption.ExistingDatabase); } return(replication); }
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(); } }
private void button1_Click(object sender, EventArgs e) { SqlCeReplication sqlCeRep = new SqlCeReplication(); string cesource = @"E:\My Project\MVC Project\Solutions\YTech.IM.JSM\app\YTech.IM.JSM.Web\DB_IM_JSM.sdf"; using (sqlCeRep) { sqlCeRep.InternetUrl = "http://localhost:81/Sync/sqlcesa35.dll"; sqlCeRep.Publisher = "yahu"; sqlCeRep.PublisherSecurityMode = SecurityType.DBAuthentication; sqlCeRep.PublisherLogin = "******"; //sqlCeRep.PublisherPassword = "******"; sqlCeRep.PublisherDatabase = "DB_IM_JSM"; sqlCeRep.Publication = "JSMPub"; sqlCeRep.Subscriber = "Rully"; sqlCeRep.SubscriberConnectionString = "Data Source=" + cesource; try { if (!System.IO.File.Exists(cesource)) { sqlCeRep.AddSubscription(AddOption.CreateDatabase); } sqlCeRep.Synchronize(); lblInfo.Text = "Synchronized."; } catch (SqlCeException sqlex) { lblInfo.Text = sqlex.Message; } catch (Exception ex) { lblInfo.Text = ex.Message; } } }
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); }