示例#1
0
        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();
            }
        }
        /// <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();
            }
        }
示例#3
0
        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 SynchronizeSqlDatabase()
        {
            //specify the location of the local device database
            string strDataPath = "\\My Documents\\IssueTracker.sdf";

            //create the data replication object
            SqlCeReplication replication = new SqlCeReplication();

            try
            {
                //define the source of the replication data
                replication.Publisher         = "server_name";
                replication.PublisherDatabase = "IssueTracker";                 //database name
                replication.Publication       = "IssueTrackerPublication";

                //define the login credentials
                replication.PublisherLogin    = "******";
                replication.PublisherPassword = "";

                //define the subscriber-side connection string
                replication.SubscriberConnectionString =
                    "Provider=Microsoft.SQLServer.OLEDB.CE.2.0;" +
                    "Data Source=" + strDataPath;

                replication.Subscriber = "iPAQ Mobile Device";

                //define the location of the IIS replication service agent
                replication.InternetUrl = "http://jkanalakis/sqlce/ssceca20.dll";

                //define the replication mode and begin the process
                replication.ExchangeType = ExchangeType.BiDirectional;
                replication.Synchronize();
            }
            catch (SqlCeException x)
            {
                MessageBox.Show(x.Message);
            }
            catch (Exception x)
            {
                MessageBox.Show(x.Message);
            }

            return;
        }
示例#5
0
        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);
        }