diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs index a017486..f876b3b 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs @@ -214,7 +214,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS else if (string.IsNullOrWhiteSpace(selectedbackupfilepath)) goto enterpathtobackupfileloop; } - SQLDataBaseManagerCore.RestoreBackup(sqld, selectedbackupfilepath, targetdirectorypath, restorefromzip, targetdbname); + SQLDataBaseManagerCore.RestoreBackup(sqld.SQLCS_Primary, selectedbackupfilepath, targetdirectorypath, restorefromzip, targetdbname); ColorConsole.WriteLine($"Database '{sqld.DBName}' restored to '{targetdbname}' into directory '{targetdirectorypath}'.", ConsoleColor.Green); } catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); } @@ -252,7 +252,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS if (targetdirectorypath.ToUpper() == "EX") { return o; } if (string.IsNullOrWhiteSpace(selectedbackupfilepath)) { targetdbname = st.DBName; } bool restorefromzip =Path.GetExtension(selectedbackupfilepath).ToLower() == ".zip"; ; - SQLDataBaseManagerCore.RestoreBackup(st, selectedbackupfilepath, targetdirectorypath, restorefromzip, targetdbname); + SQLDataBaseManagerCore.RestoreBackup(st.SQLCS_Primary, selectedbackupfilepath, targetdirectorypath, restorefromzip, targetdbname); ColorConsole.WriteLine($"Database '{targetdbname}' restored into directory '{targetdirectorypath}'.", ConsoleColor.Green); goto startselection; } @@ -443,7 +443,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS if (!srvrlogintoexecute.Remove) { - SQLDataBaseManagerCore.CreateLogin(sqlcs, srvrlogintoexecute.LoginName, srvrlogintoexecute.LoginPassword, srvrlogintoexecute.DefaultDatabase, srvrlogintoexecute.LoginType, null, srvrlogintoexecute.GrantorUserLoginName, srvrlogintoexecute.GrantorUserLoginPassword); + SQLDataBaseManagerCore.CreateLogin(sqlcs,sqldbname:null, srvrlogintoexecute.LoginName, srvrlogintoexecute.LoginPassword, srvrlogintoexecute.DefaultDatabase, srvrlogintoexecute.LoginType, null, srvrlogintoexecute.GrantorUserLoginName, srvrlogintoexecute.GrantorUserLoginPassword); ColorConsole.WriteLine($"SUCCESS! {removeactionText} server login: {SRVRLogin_fulldesignation}", ConsoleColor.Green); } else @@ -604,7 +604,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS if (!dbusertoexecute.Remove) { - SQLDataBaseManagerCore.CreateUser(sqlcs, dbusertoexecute.UserName, dbusertoexecute.RoleNameCommaList, dbusertoexecute.LoginName); + SQLDataBaseManagerCore.CreateUser(sqlcs,sqldbname:null, dbusertoexecute.UserName, dbusertoexecute.RoleNameCommaList, dbusertoexecute.LoginName); ColorConsole.WriteLine($"SUCCESS! {removeactionText} database user: {DBUser_fulldesignation}", ConsoleColor.Green); } else @@ -630,25 +630,25 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS { var DateTimeNow = DateTime.Now; SQLDataBase dbtomove = null; - - movedatabaseloop: - (Menu.SelectionResult selectionresult, bool yes) yesornoanswer = YesOrNo(new List() { $"Do You want to move ANY database from local server to remote server?" }); + string todbname=null; + movedatabaseloop: + (Menu.SelectionResult selectionresult, bool yes) yesornoanswer = YesOrNo(new List() { $">>>> Do You want to move ANY database from local server to remote server?" }); if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { - var dbselection = SelectDbToMove(config, selectedsqldbindexes, $"Select the SQL database to move from its PRIMARY to SECONDARY location!"); + var dbselection = SelectDbToMove(config, selectedsqldbindexes, $">>>> Select the SQL database to move from its PRIMARY to SECONDARY location!"); if (dbselection.selection == Menu.SelectionResult.Exit) { return o; } if (dbselection.selection != Menu.SelectionResult.Ok) { goto movedatabaseloop; } dbtomove = dbselection.dbtomove; if (NoDBNameSpecified(dbtomove)) { continue; } var dbnameSecondary = SQLDataBaseManagerCore.GetDBName(dbtomove.SQLCS_Secondary); - var todbname = ColorConsole.ReadLine($"Enter the name of the target DB. EMPTY={dbnameSecondary}, EX=exit."); + todbname = ColorConsole.ReadLine($">>>> Enter the name of the target DB. EMPTY={dbnameSecondary}, EX=exit."); if (todbname.ToUpper() == "EX") { return o; } else if (string.IsNullOrWhiteSpace(todbname)) todbname = dbnameSecondary; confirmloop:; - var confirmtext = ColorConsole.ReadLine("Enter CONFIRM to start, EX to exit, SKIP to skip."); + var confirmtext = ColorConsole.ReadLine(">>>> Enter CONFIRM to start, EX to exit, SKIP to skip."); if (confirmtext.ToUpper() == "EX") { return o; } else if (confirmtext.ToUpper() == "CONFIRM") { @@ -659,41 +659,45 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS } serverloginloop: - yesornoanswer = YesOrNo(new List() { $"Do You want to create server and DB logins for the server/database PRIMARY and/or SECONDARY locations?", }); + yesornoanswer = YesOrNo(new List() { $">>>> Do You want to create server and DB logins for the server/database PRIMARY and/or SECONDARY locations?", }); if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { if (dbtomove == null) { - var dbselection = SelectDbToMove(config, selectedsqldbindexes, $"Select the SQL database to add server and DB logins to its PRIMARY and its SECONDARY location!"); + var dbselection = SelectDbToMove(config, selectedsqldbindexes, $">>>> Select the SQL database to add server and DB logins to its PRIMARY and its SECONDARY location!"); if (dbselection.selection == Menu.SelectionResult.Exit) { return o; } if (dbselection.selection != Menu.SelectionResult.Ok) { goto serverloginloop; } dbtomove = dbselection.dbtomove; } - var usernamelist = new string[] { "corplear\\lschwirg", "corplear\\gen_vrhalmadmin", $"corplear\\{Program.ThisComputer.ComputerName}$" }; - string l1 = $"Do You want to create the following mandatory server/database logins for the PRIMARY location?"; + var usernamelist = new List { "corplear\\lschwirg", "corplear\\gen_vrhalmadmin", $"corplear\\{Program.ThisComputer.ComputerName}$" }; + if (!string.IsNullOrWhiteSpace(dbtomove.Xml_PrimaryDB_ServerName)) usernamelist.Add( $"corplear\\{dbtomove.Xml_PrimaryDB_ServerName}$"); + if (!string.IsNullOrWhiteSpace(dbtomove.Xml_SecondaryDB_ServerName)) usernamelist.Add($"corplear\\{dbtomove.Xml_SecondaryDB_ServerName}$"); + + string l1 = $">>>> Do You want to create the following mandatory server/database logins for the PRIMARY location?"; string l2 = $" SQL connection string: {dbtomove.SQLCS_Primary}"; string l3 = $" Username list: " + string.Join(",", usernamelist); - yesornoanswer = YesOrNo(new List() { l1, l2, l3, }); + yesornoanswer = YesOrNo(new List() { l1, l2, l3 }); if (yesornoanswer.selectionresult== Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { - SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbtomove.SQLCS_Primary, usernamelist, serverloginrolelist, fullaccessdbloginrolelist); + SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbtomove.SQLCS_Primary, null, usernamelist.ToArray(), serverloginrolelist, fullaccessdbloginrolelist); } - string l13 = $"Do You want to create the following mandatory server/database logins for SECONDARY location?"; + string l13 = $">>>> Do You want to create the following mandatory server/database logins for SECONDARY location?"; string l23 = $" SQL connection string: {dbtomove.SQLCS_Secondary}"; - string l33 = $" Username list: " + string.Join(",", usernamelist); - yesornoanswer = YesOrNo(new List() { l13,l23,l33,}); + string l33 = $" SQL database name: {todbname}"; + string l43 = $" Username list: " + string.Join(",", usernamelist); + yesornoanswer = YesOrNo(new List() { l13,l23,l33,l43}); if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { - SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbtomove.SQLCS_Secondary, usernamelist, serverloginrolelist, fullaccessdbloginrolelist); + SQLDataBaseManagerCore.CreateServerAndDBLogins(false, dbtomove.SQLCS_Secondary, todbname, usernamelist.ToArray(), serverloginrolelist, fullaccessdbloginrolelist); } } - yesornoanswer = YesOrNo(new List() { $"Do You want to set database '{SQLDataBaseManagerCore.GetDBName(dbtomove.SQLCS_Primary)}' OFFLINE on server '{SQLDataBaseManagerCore.GetDataSource(dbtomove.SQLCS_Primary)}'?", }); + yesornoanswer = YesOrNo(new List() { $">>>> Do You want to set database '{SQLDataBaseManagerCore.GetDBName(dbtomove.SQLCS_Primary)}' OFFLINE on server '{SQLDataBaseManagerCore.GetDataSource(dbtomove.SQLCS_Primary)}'?", }); if (yesornoanswer.selectionresult == Menu.SelectionResult.Exit) return o; if (yesornoanswer.selectionresult == Menu.SelectionResult.Ok && yesornoanswer.yes) { @@ -1291,10 +1295,7 @@ GO ColorConsole.Write(st.Status.ToString(), statuscolor, bracket: "[]", prefix: " ", suffix: ". "); if (!string.IsNullOrWhiteSpace(st.DBName)) { ColorConsole.Write(st.DBName, statuscolor, bracket: "[]", prefix: "Database ", suffix: ". "); } ColorConsole.Write(st.DataSource, statuscolor, bracket: "[]", prefix: "from server ", suffix: ". "); - if (st.Status != SQLDataBase.SQLDBStatus.NoAccess) - { - } - if (st.Xml_PrimaryDB_IsUseTranzit) { ColorConsole.Write("REMOTE", ConsoleColor.Cyan, bracket: "[]", prefix: "", suffix: ""); } + if (st.Status != SQLDataBase.SQLDBStatus.NoAccess) {} ColorConsole.WriteLine(); return Menu.MenuItemDisplayerReturnValue.NEXTLINE; } @@ -1314,21 +1315,59 @@ GO } else if (lineix == 3) { + const string STANDARD = "STANDARD"; if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; var PhysicalFilesDirectoryPathcolor = st.PrimaryDB_PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; - ColorConsole.Write($"{st.PrimaryDB_PhysicalFilesDirectoryPath}", PhysicalFilesDirectoryPathcolor, prefix: "DB files physical location:", suffix: " "); + ColorConsole.Write($"{st.PrimaryDB_PhysicalFilesDirectoryPath??STANDARD}", PhysicalFilesDirectoryPathcolor, prefix: "DB files PHYSICAL location:", suffix: " "); ColorConsole.WriteLine(" "); return Menu.MenuItemDisplayerReturnValue.NEXTLINE; } - else if (lineix == 4) - { + else if (lineix == 4) + { if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; - var SizeStringcolor = st.SizeString.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; - ColorConsole.Write(st.SizeString, SizeStringcolor, prefix: "DB size:", suffix: " "); - ColorConsole.WriteLine(" "); - return Menu.MenuItemDisplayerReturnValue.NEXTLINE; - } - else if (5 <= lineix && lineix <= 5 + st.Xml_SQLScriptList.Count) + if (!st.Xml_PrimaryDB_IsUseTranzit) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + var TranzitDirectoryPathcolor = st.Xml_PrimaryDB_TranzitDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + ColorConsole.Write($"{st.Xml_PrimaryDB_TranzitDirectoryPath}", TranzitDirectoryPathcolor, prefix: "DB files TRANZIT location:", suffix: " "); + ColorConsole.WriteLine(" "); + return Menu.MenuItemDisplayerReturnValue.NEXTLINE; + } + else if (lineix == 5) + { + if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + var SizeStringcolor = st.SizeString_Primary.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + ColorConsole.Write(st.SizeString_Primary, SizeStringcolor, prefix: "DB size:", suffix: " "); + ColorConsole.WriteLine(" "); + return Menu.MenuItemDisplayerReturnValue.NEXTLINE; + } + else if (lineix == 6) + { + if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + if (!st.Xml_SecondaryDB_IsDefined) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + ColorConsole.Write($"{st.SQLCS_Secondary}", ConsoleColor.Yellow, prefix: "Secondary SQL DB connection:", suffix: ", "); + ColorConsole.WriteLine(" "); + return Menu.MenuItemDisplayerReturnValue.NEXTLINE; + } + else if (lineix == 7) + { + const string STANDARD = "STANDARD"; + if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + if (!st.Xml_SecondaryDB_IsDefined) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + var PhysicalFilesDirectoryPathcolor = st.SecondaryDB_PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + ColorConsole.Write($"{st.SecondaryDB_PhysicalFilesDirectoryPath??STANDARD}", PhysicalFilesDirectoryPathcolor, prefix: "Secondary DB files PHYSICAL location:", suffix: " "); + ColorConsole.WriteLine(" "); + return Menu.MenuItemDisplayerReturnValue.NEXTLINE; + } + else if (lineix == 8) + { + if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + if (!st.Xml_SecondaryDB_IsDefined) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + if (!st.Xml_SecondaryDB_IsUseTranzit) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + var TranzitDirectoryPathcolor = st.Xml_SecondaryDB_TranzitDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + ColorConsole.Write($"{st.Xml_SecondaryDB_TranzitDirectoryPath}", TranzitDirectoryPathcolor, prefix: "Secondary DB files TRANZIT location:", suffix: " "); + ColorConsole.WriteLine(" "); + return Menu.MenuItemDisplayerReturnValue.NEXTLINE; + } + else if (9 <= lineix && lineix <= 9 + st.Xml_SQLScriptList.Count) { if (st.Xml_SQLScriptList.Count == 0) { return Menu.MenuItemDisplayerReturnValue.EXIT; } if (st.Xml_SQLScriptList.Count-1 < lineix-5) { return Menu.MenuItemDisplayerReturnValue.EXIT; } @@ -1358,7 +1397,7 @@ GO { var dbbackupfilepath = CreateBackup(sqld, false,null); if (dbbackupfilepath == null) return; - RestoreBackup(sqld, dbbackupfilepath, targetdirectory, false, restoredbname); + RestoreBackup(sqld.SQLCS_Primary, dbbackupfilepath, targetdirectory, false, restoredbname); if (File.Exists(dbbackupfilepath)) { File.Delete(dbbackupfilepath); } } @@ -1378,18 +1417,18 @@ GO if (!emulation && !File.Exists(backupfileFullname)) { return false; } - string tranzitfileFullname = backupfileFullname; - if (dbtomove.Xml_SecondaryDB_IsUseTranzit) + string tranzitfileNetworkFullname = backupfileFullname; + if (dbtomove.Xml_SecondaryDB_IsUseTranzit) { try { string backupfileFilename = Path.GetFileName(backupfileFullname); - tranzitfileFullname = Path.Combine(dbtomove.Xml_SecondaryDB_TranzitDirectoryPath, backupfileFilename); + tranzitfileNetworkFullname = Path.Combine(dbtomove.Xml_SecondaryDB_TranzitDirectoryPath, backupfileFilename); ColorConsole.WriteLine($"Moving backup file {backupfileFullname} to tranzit location: {dbtomove.Xml_SecondaryDB_TranzitDirectoryPath}", ConsoleColor.Yellow); if (!emulation) { - if (File.Exists(tranzitfileFullname)) { File.Delete(tranzitfileFullname); } - File.Move(backupfileFullname, tranzitfileFullname); + if (File.Exists(tranzitfileNetworkFullname)) { File.Delete(tranzitfileNetworkFullname); } + File.Move(backupfileFullname, tranzitfileNetworkFullname); ColorConsole.WriteLine($"...completed...", ConsoleColor.Yellow); } } @@ -1400,10 +1439,10 @@ GO return false; } } - if (!emulation && !File.Exists(tranzitfileFullname)) { return false; } + if (!emulation && !File.Exists(tranzitfileNetworkFullname)) { return false; } //restore backup to dbto - SQLDataBaseManagerCore.RestoreBackup(dbtomove, tranzitfileFullname, dbtomove.Xml_SecondaryDB_PhysicalFilesDirectoryPath, false, selecteddbname, emulation); + SQLDataBaseManagerCore.RestoreBackup(dbtomove.SQLCS_Secondary, tranzitfileNetworkFullname, dbtomove.Xml_SecondaryDB_PhysicalFilesDirectoryPath, false, selecteddbname, emulation); return true; } @@ -1416,19 +1455,22 @@ GO /// true=sourcesqlbackupfilepath is a zip file /// /// - public static void RestoreBackup(SQLDataBase sqldb, string sourcesqlbackupfilepath, string targetdbphysicalfilesdirectorypath, bool restorefromZIP = false, string restoretodbname = null,bool emulate=false) + public static void RestoreBackup(string sqldbcs, string sourcesqlbackupfilepath, string targetdbphysicalfilesdirectorypath, bool restorefromZIP = false, string restoretodbname = null,bool emulate=false) { - string sqlcs = sqldb.SQLCS_Primary; //sqlcs = sqlcs.Replace("LearALM2", "master"); + string sqlcs = sqldbcs; //sqlcs = sqlcs.Replace("LearALM2", "master"); string zippedbackupfilepath = restorefromZIP? sourcesqlbackupfilepath:Path.Combine(Path.GetDirectoryName(sourcesqlbackupfilepath), Path.GetFileNameWithoutExtension(sourcesqlbackupfilepath) + ".zip"); string normalbackupfilepath = !restorefromZIP? sourcesqlbackupfilepath : Path.Combine(Path.GetDirectoryName(sourcesqlbackupfilepath), Path.GetFileNameWithoutExtension(sourcesqlbackupfilepath) + ".bak"); ColorConsole.WriteLine(nameof(RestoreBackup), ConsoleColor.Yellow, prefix: "running...."); ColorConsole.WriteLine(restoretodbname, ConsoleColor.Yellow, prefix: " restoretodbname:"); - ColorConsole.WriteLine(sqldb.SQLCS_Primary, ConsoleColor.Yellow, prefix: " sqldb.SQLCS:"); + ColorConsole.WriteLine(sqldbcs, ConsoleColor.Yellow, prefix: " sqldb.SQLCS:"); ColorConsole.WriteLine(sourcesqlbackupfilepath, ConsoleColor.Yellow, prefix: " sourcesqlbackupfilepath:"); - ColorConsole.WriteLine(normalbackupfilepath, ConsoleColor.Yellow, prefix: " backupfilepath:"); - ColorConsole.WriteLine(restorefromZIP.ToString(), ConsoleColor.Yellow, prefix: " restorefromZIP:"); - ColorConsole.WriteLine(zippedbackupfilepath, ConsoleColor.Yellow, prefix: " zippedbackupfilepath:"); + ColorConsole.WriteLine(restorefromZIP.ToString(), ConsoleColor.Yellow, prefix: " restorefromZIP:"); + if (restorefromZIP) + { + ColorConsole.WriteLine(normalbackupfilepath, ConsoleColor.Yellow, prefix: " backupfilepath:"); + ColorConsole.WriteLine(zippedbackupfilepath, ConsoleColor.Yellow, prefix: " zippedbackupfilepath:"); + } ColorConsole.WriteLine(targetdbphysicalfilesdirectorypath, ConsoleColor.Yellow, prefix: " targetdbphysicalfilesdirectorypath:"); if (emulate) { return; } @@ -1444,18 +1486,14 @@ GO while (DateTime.Now.Subtract(starttime).TotalSeconds > 5) { if (File.Exists(normalbackupfilepath)) { break; } Thread.Sleep(500); } } - if (!File.Exists(normalbackupfilepath)) - { - ColorConsole.WriteLine($"ERROR! Restore source backup file '{normalbackupfilepath}' does not exist!", ConsoleColor.Red, prefix: ""); - return; - } Server sqlserver = null; try { var sc = ServerConnectionPool.GetSqlConnection(sqlcs, "master"); sqlserver = SQLServerConnect(sc);if (sqlserver == null) { return; } + sqlserver.ConnectionContext.StatementTimeout = 2000;// sqld.Xml_BackupTimeout; - var smoRestore = new Restore(); + var smoRestore = new Restore(); smoRestore.NoRecovery = false; smoRestore.ReplaceDatabase = true; smoRestore.Action = RestoreActionType.Database; @@ -1588,9 +1626,10 @@ GO sqlserver = SQLServerConnect(sqld.SQLCS_Primary, "master"); if (sqlserver == null) { return null; } sqlserver.ConnectionContext.StatementTimeout = sqld.Xml_BackupTimeout; backupstarttime = DateTime.Now; - smoBackup.SqlBackup(sqlserver); - //smoBackup.Wait(); - Console.WriteLine($""); + smoBackup.SqlBackupAsync(sqlserver); + smoBackup.Wait(); + //smoBackup.Wait(); + Console.WriteLine($""); Console.WriteLine($"Backup completed. Backup time: {(int)(DateTime.Now.Subtract(backupstarttime).TotalSeconds)}sec."); } catch (Exception ex) @@ -1672,9 +1711,9 @@ GO } finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } } - public static void CreateUser(string sqldbconnectionString, string dbusername, string dbrolenamecommalist,string loginname) + public static void CreateUser(string sqldbconnectionString, string sqldbname, string dbusername, string dbrolenamecommalist,string loginname) { - using (SqlConnection connection = ServerConnectionPool.GetSqlConnection(sqldbconnectionString,open:true)) + using (SqlConnection connection = ServerConnectionPool.GetSqlConnection(sqldbconnectionString, sqldbname,open: true)) { // Create user //USE [LearALM2] @@ -1758,12 +1797,12 @@ GO } } - public static void CreateLogin(string sqldbconnectionString, string name, string password, string defaultDatabase, LoginType logintype, string[] roles,string grantoruser=null,string grantoruserpsw=null) + public static void CreateLogin(string sqldbconnectionString,string sqldbname, string name, string password, string defaultDatabase, LoginType logintype, string[] roles,string grantoruser=null,string grantoruserpsw=null) { Server sqlserver = null; try { - var sc = ServerConnectionPool.GetSqlConnection(sqldbconnectionString,null, grantoruser, grantoruserpsw); + var sc = ServerConnectionPool.GetSqlConnection(sqldbconnectionString, sqldbname, grantoruser, grantoruserpsw); sqlserver = SQLServerConnect(sc); if (sqlserver == null) return; Login login = new Login(sqlserver, name); login.LoginType = logintype; @@ -1782,14 +1821,14 @@ GO } finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } } - public static void CreateServerAndDBLogins(bool emulation, string sqlcs, string[] usernamelist,string[] serverloginrolelist, string[] dbloginrolelist) + public static void CreateServerAndDBLogins(bool emulation, string sqlcs,string dbname, string[] usernamelist,string[] serverloginrolelist, string[] dbloginrolelist) { foreach (var username in usernamelist) { ColorConsole.WriteLine(username, ConsoleColor.Yellow, prefix: nameof(SQLDataBaseManagerCore.CreateServerAndDBLogins) + ":"); - try { if (!emulation) SQLDataBaseManagerCore.CreateLogin(sqlcs, username, null, "master", LoginType.WindowsUser, serverloginrolelist); } + try { if (!emulation) SQLDataBaseManagerCore.CreateLogin(sqlcs, dbname, username, null, "master", LoginType.WindowsUser, serverloginrolelist); } catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateLogin) + ">>>: " + ex.MessageNested(), ConsoleColor.Red); } - try { if (!emulation) SQLDataBaseManagerCore.CreateUser(sqlcs, username, string.Join(",", dbloginrolelist), "w"); } + try { if (!emulation) SQLDataBaseManagerCore.CreateUser(sqlcs, dbname, username, string.Join(",", dbloginrolelist), "w"); } catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateUser) + "\n" + ex.MessageNested(), ConsoleColor.Red); } } } @@ -1925,7 +1964,12 @@ GO var sqlcb = new SqlConnectionStringBuilder(cs); return sqlcb.InitialCatalog; } - public static string GetDataSource(string cs) + public static string GetDBServerName(string cs) + { + var sqlcb = new SqlConnectionStringBuilder(cs); + return sqlcb. DataSource; + } + public static string GetDataSource(string cs) { var sqlcb = new SqlConnectionStringBuilder(cs); return sqlcb.DataSource; @@ -2635,6 +2679,7 @@ GO public int Xml_ScriptCommandTimeout; public int Xml_BackupTimeout; + public string Xml_PrimaryDB_ServerName; public string Xml_PrimaryDB_SQLConnectionString; public string Xml_PrimaryDB_TranzitDirectoryPath; public bool Xml_PrimaryDB_IsUseTranzit { get { return !string.IsNullOrWhiteSpace(Xml_PrimaryDB_TranzitDirectoryPath); } } @@ -2675,9 +2720,12 @@ GO } } + public string Xml_SecondaryDB_ServerName; public string Xml_SecondaryDB_SQLConnectionString; public string Xml_SecondaryDB_TranzitDirectoryPath; - public bool Xml_SecondaryDB_IsUseTranzit { get { return !string.IsNullOrWhiteSpace(Xml_SecondaryDB_TranzitDirectoryPath); } } + + public bool Xml_SecondaryDB_IsDefined { get { return !string.IsNullOrWhiteSpace(Xml_SecondaryDB_SQLConnectionString); } } + public bool Xml_SecondaryDB_IsUseTranzit { get { return !string.IsNullOrWhiteSpace(Xml_SecondaryDB_TranzitDirectoryPath); } } public string Xml_SecondaryDB_PhysicalFilesDirectoryPath; public string SQLCS_Secondary { @@ -2698,9 +2746,11 @@ GO public string DataSource; public SQLDBStatus Status; public string PrimaryDB_PhysicalFilesDirectoryPath; - public string SizeString; - #endregion fields - public enum SQLDBStatus { NoAccess, OK, } + public string SecondaryDB_PhysicalFilesDirectoryPath; + public string SizeString_Primary; + public string SizeString_Secondary; + #endregion fields + public enum SQLDBStatus { NoAccess, OK, } #region CollectInfo public SQLDataBase CollectInfo() @@ -2725,8 +2775,9 @@ GO } else { - GetPhysicalFilesLocationAndSize(this.SQLCS_Primary, out this.SizeString, out this.PrimaryDB_PhysicalFilesDirectoryPath); - this.Status = this.PrimaryDB_PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK; + GetPhysicalFilesLocationAndSize(this.SQLCS_Primary, out this.SizeString_Primary, out this.PrimaryDB_PhysicalFilesDirectoryPath); + GetPhysicalFilesLocationAndSize(this.SQLCS_Secondary, out this.SizeString_Secondary, out this.SecondaryDB_PhysicalFilesDirectoryPath); + this.Status = this.PrimaryDB_PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK; this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS_Primary); this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS_Primary); } @@ -2736,10 +2787,12 @@ GO { this.Status = SQLDBStatus.NoAccess; this.PrimaryDB_PhysicalFilesDirectoryPath = ""; + this.SecondaryDB_PhysicalFilesDirectoryPath = ""; this.DBName = ""; this.DataSource = ""; - this.SizeString = ""; - try + this.SizeString_Primary = ""; + this.SizeString_Secondary = ""; + try { this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS_Primary); this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS_Primary); @@ -2760,6 +2813,7 @@ GO { dbsizetext = null; dbpathtext = null; + if (string.IsNullOrWhiteSpace(sqlconnectionstring)) { return; } try { var sqlc = ServerConnectionPool.GetSqlConnection(sqlconnectionstring,open:true); @@ -2821,9 +2875,11 @@ GO Xml_RestoreFileNameMask = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.RestoreFileNameMask), sqldatabasexml, common.Xml_RestoreFileNameMask); Xml_BackupTargetDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.BackupTargetDirectoryPath), sqldatabasexml, common.Xml_BackupTargetDirectoryPath); Xml_PrimaryDB_TranzitDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.TranzitDirectoryNetworkPath), sqldatabasexml, common.Xml_PrimaryDB_TranzitDirectoryPath); + Xml_PrimaryDB_ServerName = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.Server), sqldatabasexml, XmlStructure.SQLDataBase.Attributes.Server.Values.DEFAULT); Xml_PrimaryDB_SQLConnectionString = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.SQLConnectionString), sqldatabasexml, XmlStructure.SQLDataBase.Attributes.SQLConnectionString.Values.DEFAULT); var secdbxml = GetXElement(sqldatabasexml,nameof(XmlStructure.SQLDataBase.SecondaryDB)); + Xml_SecondaryDB_ServerName = GetValue(nameof(XmlStructure.SQLDataBase.SecondaryDB.Attributes.Server), secdbxml, ""); Xml_SecondaryDB_SQLConnectionString = GetValue(nameof(XmlStructure.SQLDataBase.SecondaryDB.Attributes.SQLConnectionString), secdbxml, ""); Xml_SecondaryDB_TranzitDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.SecondaryDB.Attributes.TranzitDirectoryNetworkPath), secdbxml, ""); Xml_SecondaryDB_PhysicalFilesDirectoryPath = GetValue(nameof(XmlStructure.SQLDataBase.SecondaryDB.Attributes.PhysicalFilesDirectoryPath), secdbxml, ""); @@ -2899,6 +2955,7 @@ GO { public static class Key { public static class Values { public const string DEFAULT = ""; } } public static class Description { } + public static class Server { public static class Values { public const string DEFAULT = ""; } } public static class SQLConnectionString { public static class Values { public const string DEFAULT = ""; } } public static class BackupFileNameMask { } public static class RestoreFileNameMask { } @@ -2976,9 +3033,11 @@ GO { public static class Attributes { + public static class TranzitDirectoryLocalPath { public static class Values { public const string DEFAULT = ""; } } public static class TranzitDirectoryNetworkPath { public static class Values { public const string DEFAULT = ""; } } public static class PhysicalFilesDirectoryPath { public static class Values { public const string DEFAULT = ""; } } public static class SQLConnectionString { public static class Values { public const string DEFAULT = null; } } + public static class Server { public static class Values { public const string DEFAULT = null; } } } } } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index cce0e24..b8849fc 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.32.0.0")] -[assembly: AssemblyFileVersion("1.32.0.0")] +[assembly: AssemblyVersion("1.33.0.0")] +[assembly: AssemblyFileVersion("1.33.0.0")] -- libgit2 0.21.2