Пример #1
0
        private void copyServerTriggers(Server destserver, bool disableonsource, bool disableondest, bool dropdest)
        {
            ServerDdlTriggerCollection desttriggers = destserver.Triggers;

            foreach (ServerDdlTrigger trigger in sourceserver.Triggers)
            {
                string     triggername = trigger.Name;
                ItemToCopy item        = itemsToCopy.Find(x => x.Name == triggername);
                if (item.IsChecked)
                {
                    if (desttriggers[triggername] != null)
                    {
                        if (!dropdest)
                        {
                            showOutput.displayOutput(string.Format("Trigger {0} already exists in destination. Skipping.", triggername));
                            continue;
                        }
                        try
                        {
                            showOutput.displayOutput(string.Format("Dropping trigger {0}.", triggername));
                            ServerDdlTrigger desttrigger = desttriggers[triggername];
                            desttriggers[triggername].Drop();
                            desttriggers.Refresh();
                        }
                        catch (Exception ex)
                        {
                            showOutput.displayOutput(ex.Message);
                            continue;
                        }
                    }

                    try
                    {
                        StringCollection sql = trigger.Script();
                        destserver.ConnectionContext.ExecuteNonQuery(sql);
                        destserver.Triggers.Refresh();
                        showOutput.displayOutput(string.Format("Copied trigger {0} to {1}", triggername, destserver.Name));

                        if (disableonsource)
                        {
                            trigger.IsEnabled = false;
                            trigger.Alter();
                        }

                        if (disableondest)
                        {
                            destserver.Triggers[triggername].IsEnabled = false;
                            destserver.Triggers[triggername].Alter();
                            desttriggers.Refresh();
                        }
                    }
                    catch (Exception ex)
                    {
                        showOutput.displayOutput(string.Format("Error copying trigger {0} to {1}", triggername, destserver.Name));
                        showOutput.displayOutput(ex.Message);
                        continue;
                    }
                }
            }
        }
Пример #2
0
        internal static string GetStatus(object context)
        {
            Trigger trigger = context as Trigger;

            if (trigger != null)
            {
                if (!trigger.IsEnabled)
                {
                    return("Disabled");
                }
            }

            ServerDdlTrigger serverDdlTrigger = context as ServerDdlTrigger;

            if (serverDdlTrigger != null)
            {
                if (!serverDdlTrigger.IsEnabled)
                {
                    return("Disabled");
                }
            }

            DatabaseDdlTrigger databaseDdlTrigger = context as DatabaseDdlTrigger;

            if (databaseDdlTrigger != null)
            {
                if (!databaseDdlTrigger.IsEnabled)
                {
                    return("Disabled");
                }
            }

            return(string.Empty);
        }