1: public void AddReplAndSync()
2: {
3: //using System.Data.SqlServerCe;
4: bool bAddRepl = false;
5: try
6: {
7: if (DoDBLookup("SELECT
count(*) as cRow FROM __sysMergeSubscriptions WHERE Subscriber='ExhibitorSubscription'", "cRow")
!= "1")
8: {
9: bAddRepl = true;
10: }
11: }
12: catch
13: {
14: bAddRepl = true;
15: }
16:
17: SqlCeReplication repl = new SqlCeReplication();
18: repl.InternetUrl = AppSettings.Settings.ReplServer
+ "sqlcesa35.dll";
19: repl.InternetLogin = AppSettings.Settings.ReplUser;
20: repl.InternetPassword = "XXXXXX";
21:
22: repl.Publisher = AppSettings.Settings.ReplPublisher;
23: repl.PublisherDatabase = AppSettings.Settings.ReplPubDB;
24: repl.PublisherSecurityMode = SecurityType.NTAuthentication;
25: repl.Publication = AppSettings.Settings.ReplPubName;
26: repl.Subscriber = AppSettings.Settings.ReplSubName;
27: repl.SubscriberConnectionString = string.Format("DATA
SOURCE='{0}'", ESDAL.GetDBPath());
28:
29: try
30: {
31: if (bAddRepl)
32: repl.AddSubscription(AddOption.ExistingDatabase);
33: CloseAllDBConnections();
34: repl.Synchronize();
35: }
36: catch (SqlCeException
e)
37: {
38: MessageBox.Show(e.ToString() + e.NativeError.ToString());
39: }
40:
41: }
42:
43: public void ReplRemove()
44: {
45: CloseAllDBConnections();
46: SqlCeReplication repl = new SqlCeReplication();
47: repl.SubscriberConnectionString = string.Format("DATA
SOURCE='{0}'", ESDAL.GetDBPath());
48: repl.InternetUrl = AppSettings.Settings.ReplServer
+ "sqlcesa35.dll";
49: repl.InternetLogin = AppSettings.Settings.ReplUser;
50: repl.InternetPassword = "XXXXXX";
51: repl.Publisher = AppSettings.Settings.ReplPublisher;
52: repl.PublisherDatabase = AppSettings.Settings.ReplPubDB;
53: repl.PublisherSecurityMode = SecurityType.NTAuthentication;
54: repl.Publication = AppSettings.Settings.ReplPubName;
55: repl.Subscriber = AppSettings.Settings.ReplSubName;
56: try
57: {
58: CloseAllDBConnections();
59: repl.DropSubscription(DropOption.LeaveDatabase);
60: }
61: catch (SqlCeException
e)
62: {
63: MessageBox.Show(e.ToString() + e.NativeError.ToString());
64: }
65: }
66:
67: private void CloseAllDBConnections()
68: {
69: if ((_dbCon != null)
&& (_dbCon.State != ConnectionState.Closed))
70: {
71: _dbCon.Dispose();
72: _dbCon = null;
73: GC.Collect();
74: }
75:
76: }