}//public static void Main() ///<summary>AdmonishAdminister().</summary> public static void AdmonishAdminister ( ref ArrayList taskList, ref String exceptionMessage, ref StringBuilder sb ) { SQLDMOTypeLib.NameList sQLDMOTypeLibNameList = null; sb = new StringBuilder(); foreach (object taskListCurrent in taskList) { switch (( string )taskListCurrent) { case "NameList": NameList ( ref sQLDMOTypeLibNameList, ref exceptionMessage, ref sb ); break; } //switch ( taskListCurrent ) } //foreach( string taskListCurrent in taskList ) } //public static void AdmonishAdminister
} //public static void AdmonishAdminister ///<summary>NameList().</summary> public static void NameList ( ref SQLDMOTypeLib.NameList sQLDMOTypeLibNameList, ref string exceptionMessage, ref StringBuilder sb ) { try { sQLDMOTypeLibNameList = SQLDMOTypeLibApplication.ListAvailableSQLServers(); if (sQLDMOTypeLibNameList == null) { return; } #if (DEBUG) if (sQLDMOTypeLibNameList.Count > 0) { sb.Append("<b>SQLServer NameList</b><br/>"); } foreach (object sQLDMOTypeLibNameListCurrent in sQLDMOTypeLibNameList) { System.Console.WriteLine("SQLServer NameList: " + sQLDMOTypeLibNameListCurrent); sb.Append(sQLDMOTypeLibNameListCurrent); sb.Append("<br/>"); } //foreach( object sQLDMOTypeLibNameListCurrent in sQLDMOTypeLibNameList ) #endif } //try catch (System.Exception exception) { exceptionMessage = exception.Message; System.Console.WriteLine("Exception: {0}", exception.Message); } }//public static void NameList()
///<summary>The entry point for the application.</summary> ///<param name="argv">Command-line parameters.</param> public static void Main ( string[] argv ) { string exceptionMessage = null; ArrayList taskList = null; StringBuilder sb = null; SQLDMOTypeLib.NameList sQLDMOTypeLibNameList = null; taskList = new ArrayList(); sb = new StringBuilder(); NameList ( ref sQLDMOTypeLibNameList, ref exceptionMessage, ref sb ); foreach (string admonishCurrent in Admonish) { taskList.Add(admonishCurrent); } AdmonishAdminister ( ref taskList, ref exceptionMessage, ref sb ); ScriptServerDatabase ( ref exceptionMessage ); }//public static void Main()
}//public static void NameList() ///<summary>ScriptServerDatabase().</summary> public static void ScriptServerDatabase ( ref string exceptionMessage ) { string databaseName = null; string databaseScriptDirectory = null; string serverName = null; StringBuilder databaseScriptFilename = null; SQLDMOTypeLib.NameList sQLDMOTypeLibNameList = null; try { sQLDMOTypeLibNameList = SQLDMOTypeLibApplication.ListAvailableSQLServers(); foreach (object sQLDMOTypeLibNameListCurrent in sQLDMOTypeLibNameList) { serverName = sQLDMOTypeLibNameListCurrent.ToString(); if (string.Compare(serverName, ServerNameLocal, true) == 0) { UtilityNet.DNSDomainNameResolution ( ref serverName, ref exceptionMessage ); } SQLDMOTypeLib.SQLServer sqlServerCurrent = new SQLDMOTypeLib.SQLServerClass(); // Connect to a SQL Server Instance, use windows authentication sqlServerCurrent.LoginSecure = true; sqlServerCurrent.Connect(serverName, null, null); Console.WriteLine("Connected..."); foreach (Database2 database in sqlServerCurrent.Databases) { databaseName = database.Name; databaseScriptFilename = new StringBuilder(); databaseScriptFilename.AppendFormat ( DatabaseScriptFilename, serverName, databaseName ); databaseScriptDirectory = Path.GetDirectoryName(databaseScriptFilename.ToString()); if (Directory.Exists(databaseScriptDirectory) == false) { Directory.CreateDirectory ( databaseScriptDirectory ); }//if ( Directory.Exists( databaseScriptDirectory ) == false ) System.Console.WriteLine ( "{0}", database.Script(SQLDMO_SCRIPT_TYPE.SQLDMOScript_Default, databaseScriptFilename.ToString(), SQLDMO_SCRIPT2_TYPE.SQLDMOScript2_Default) ); } sqlServerCurrent.DisConnect(); } //foreach (Database2 database in sqlServerCurrent.Databases) } //if ( Directory.Exists( databaseScriptDirectory ) == false ) catch (System.Runtime.InteropServices.COMException exception) { exceptionMessage = exception.Message; System.Console.WriteLine("System.Runtime.InteropServices.COMException: {0}", exceptionMessage); } //catch( System.Runtime.InteropServices.COMException exception ) } //public static void ScriptServerDatabase()