Exemple #1
0
        private static void Deprovision(SelectedConfigSections selectedConfig, bool script, DirectoryInfo workingDirectory)
        {
            try
            {
                SqlSyncScopeDeprovisioning deprov =
                    new SqlSyncScopeDeprovisioning(new SqlConnection(selectedConfig.SelectedTargetDatabase.GetConnectionString()));

                // Set the ObjectSchema property.
                if (!String.IsNullOrEmpty(selectedConfig.SelectedSyncScope.SchemaName))
                {
                    deprov.ObjectSchema = selectedConfig.SelectedSyncScope.SchemaName;
                }

                Log("Deprovisioning Database {0} for scope {1}...", selectedConfig.SelectedTargetDatabase.Name,
                    selectedConfig.SelectedSyncScope.Name);

                if (selectedConfig.SelectedSyncScope.IsTemplateScope)
                {
                    if (!script)
                    {
                        deprov.DeprovisionTemplate(selectedConfig.SelectedSyncScope.Name);
                    }
                    else
                    {
                        SaveScript("deprovision.sql", deprov.ScriptDeprovisionTemplate(selectedConfig.SelectedSyncScope.Name), workingDirectory);
                    }
                }
                else
                {
                    if (!script)
                    {
                        deprov.DeprovisionScope(selectedConfig.SelectedSyncScope.Name);
                    }
                    else
                    {
                        SaveScript("deprovision.sql", deprov.ScriptDeprovisionScope(selectedConfig.SelectedSyncScope.Name), workingDirectory);
                    }
                }
            }
            catch (Exception e)
            {
                throw new InvalidOperationException(
                          "Unexpected error when executing the Deprovisioning command. See inner exception for details.", e);
            }
        }