Exemple #1
0
        private StringCollection GetScriptToMakeIdenticalObject2()
        {
            StringCollection collScript = new StringCollection();
            Server           server1    = new Server(this.serverConn2);
            Server           server2    = new Server(this.serverConn1);
            SqlSmoObject     object1    = server1.GetSmoObject(this.urnTextBox2.Text);
            SqlSmoObject     object2    = server2.GetSmoObject(this.urnTextBox1.Text);
            Database         database1  = object1 as Database;
            Database         database2  = object2 as Database;

            server1.ConnectionContext.SqlExecutionModes = SqlExecutionModes.CaptureSql;

            object1.Refresh();
            object2.Refresh();

            foreach (Property p in object2.Properties)
            {
                try
                {
                    if (p.Writable && object2.Properties[p.Name].Value != null &&
                        !object1.Properties[p.Name].Value.Equals(object2.Properties[p.Name].Value))
                    {
                        object1.Properties[p.Name].Value = object2.Properties[p.Name].Value;
                    }
                }
                catch (PropertyCannotBeRetrievedException)
                {
                    // Ignore properties that can't be accessed
                }
            }

            if (database1 != null && database2 != null)
            {
                foreach (Property p in database1.DatabaseOptions.Properties)
                {
                    // If the props differ in value update the destination database
                    if (!p.IsNull &&
                        !database1.DatabaseOptions.Properties[p.Name].IsNull &&
                        database1.DatabaseOptions.Properties[p.Name].Writable)
                    {
                        if (!database1.DatabaseOptions.Properties[p.Name].Value
                            .Equals(database2.DatabaseOptions.Properties[p.Name].Value))
                        {
                            database1.DatabaseOptions.Properties[p.Name].Value =
                                database2.DatabaseOptions.Properties[p.Name].Value;
                        }
                    }
                }
            }

            server1.ConnectionContext.CapturedSql.Clear();
            server2.ConnectionContext.CapturedSql.Clear();

            IAlterable alterableObject1 = object1 as IAlterable;

            if (alterableObject1 != null)
            {
                try
                {
                    alterableObject1.Alter();
                    collScript = server1.ConnectionContext.CapturedSql.Text;
                }
                catch (SmoException ex)
                {
                    ExceptionMessageBox emb = new ExceptionMessageBox(ex);
                    emb.Show(this);
                }
            }

            server1.ConnectionContext.SqlExecutionModes = SqlExecutionModes.ExecuteSql;
            if (collScript.Count == 0)
            {
                collScript.Add(Properties.Resources.SelectedObjectsIdentical);
            }

            return(collScript);
        }
Exemple #2
0
 public static bool ReadAlteringState(this IAlterable obj, List <ClilocItemRec> properties)
 {
     return(ClilocHelper.Contains(properties, 1111880));
 }