コード例 #1
0
 /// <summary>
 /// Script a Synonym using SMO
 /// </summary>
 /// <param name="objectName">Synonym name</param>
 /// <param name="schemaName">Schema name</param>
 /// <returns>String collection of scripts</returns>
 internal StringCollection GetSynonymScripts(string objectName, string schemaName, ScriptingOptions scriptingOptions = null)
 {
     try
     {
         Synonym smoObject = string.IsNullOrEmpty(schemaName) ? new Synonym(this.Database, objectName) : new Synonym(this.Database, objectName, schemaName);
         smoObject.Refresh();
         return((scriptingOptions == null) ? smoObject.Script() : smoObject.Script(scriptingOptions));
     }
     catch (Exception ex)
     {
         Logger.Write(LogLevel.Error, "Exception at PeekDefinition GetSynonymScripts : " + ex.Message);
         return(null);
     }
 }
コード例 #2
0
        protected void ScriptSynonyms(DbServerContext context, IEnumerable <ScriptObject> synonyms)
        {
            if ((m_options.ObjectsToInclude & ObjectTypeEnum.Synonym) == ObjectTypeEnum.Synonym)
            {
                string outputDirectory = Path.Combine(m_definitionDirectory, m_options.FolderNameSynonyms);

                foreach (ScriptObject synonymObject in synonyms)
                {
                    Synonym curentSynonym = context.Database.Synonyms[synonymObject.ObjectName, synonymObject.ObjectSchema];
                    ScriptDefinition(synonymObject, outputDirectory, new Func <StringCollection>(() =>
                    {
                        return(curentSynonym.Script(m_options.ScriptingOptions));
                    }));
                }
            }
        }