From 1369dd36970987b2a4ee79f56091a0ffbb9cdb53 Mon Sep 17 00:00:00 2001 From: Schwirg László Date: Tue, 19 Nov 2024 15:19:00 +0100 Subject: [PATCH] v1.29.2.0 - MoveDbToRemoteServer kiegészítése --- Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs | 250 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------------------------------------------------------- Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs | 4 ++-- 2 files changed, 181 insertions(+), 73 deletions(-) diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs index 1387ea7..d47ed7b 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs @@ -135,7 +135,6 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS SQLDataBase sqld = p.Parameters as SQLDataBase; try { - SQLDataBaseManagerCore.BackupSqlScripts(sqld,TS); ColorConsole.WriteLine($"SQLDB code scripts created. Name:{sqld.Xml_Description}", ConsoleColor.Green); } @@ -633,16 +632,57 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS var selectedsqldbindexes = CommandLine.GetCommandLineArgument(args, CLP.Module.SQLDataBaseManager.Function.CMD_DATABASES); - selectionloop: + (bool Exit, bool Yes) yesornoanswer; + (bool Exit, bool Yes, SQLDataBase Dbfrom, SQLDataBase Dbto, string Selecteddbname, bool Emulation) movedbanswer; + while (true) + { + var DateTimeNow = DateTime.Now; + + movedbanswer = YesOrNo_MoveDbToRemoteServer(config, selectedsqldbindexes); + if (movedbanswer.Exit) break; + if (movedbanswer.Yes) + { + var movesuccess = SQLDataBaseManagerCore.MoveDbToRemoteServer(movedbanswer.Dbfrom, movedbanswer.Dbto, movedbanswer.Selecteddbname, movedbanswer.Emulation); + if (!movesuccess) continue; + } + + var usernamelist = new string[] { "corplear\\lschwirg", "corplear\\gen_vrhalmadmin", $"corplear\\{Program.ThisComputer.ComputerName}$" }; + + yesornoanswer = YesOrNo_ServerLogin(movedbanswer.Dbfrom.SQLCS, usernamelist); + if (yesornoanswer.Exit) return o; + if (yesornoanswer.Yes) SQLDataBaseManagerCore.CreateServerLogins(movedbanswer.Emulation, movedbanswer.Dbfrom.SQLCS, usernamelist, loginrolelist,fullaccessrolelist); + + yesornoanswer = YesOrNo_ServerLogin(movedbanswer.Dbto.SQLCS, usernamelist); + if (yesornoanswer.Exit) return o; + if (yesornoanswer.Yes) SQLDataBaseManagerCore.CreateServerLogins(movedbanswer.Emulation, movedbanswer.Dbto.SQLCS, usernamelist, loginrolelist, fullaccessrolelist); + + yesornoanswer = YesOrNo_SetDbOffline(movedbanswer.Dbfrom.SQLCS, null); + if (yesornoanswer.Exit) return o; + if (yesornoanswer.Yes) SQLDataBaseManagerCore.SetDatabaseOffline(movedbanswer.Dbfrom.SQLCS); + + ColorConsole.WriteLine($"Moving DB to remote server completed. Required time: {(int)(DateTime.Now.Subtract(DateTimeNow).TotalSeconds)} seconds.", ConsoleColor.Green); + } + return o; + } + private static (bool,bool,SQLDataBase, SQLDataBase, string, bool) YesOrNo_MoveDbToRemoteServer(SQLDataBaseManagerXmlProcessor config,string selectedsqldbindexes) + { + (bool, bool, SQLDataBase, SQLDataBase, string, bool) returnvalueexit = (true, false, null, null, null, false); + + selectionloop: + + ColorConsole.WriteLine($"Do You want to move ANY database from local server to remote server?", ConsoleColor.Yellow); + var yesorno = ColorConsole.ReadLine("Move?", ConsoleColor.Yellow, validitylist: new List { "yes", "no" }, defaultvalue: "yes"); + if (yesorno.ToUpper() == "EX") return returnvalueexit; + var menufolders = DisplaySQLDataBaseMenu(config, $"Select the SQL database(s) to manage with function. '{nameof(MoveDbToRemoteServer)}'! Format:FROMLOCALDB,TOREMOTEDB", silent: true, selectionmode: Menu.SelectionMode.Multi); Menu.Selection sr = menufolders.Select(selectedsqldbindexes); - if (sr.Result == Menu.SelectionResult.Exit) { return o; } + if (sr.Result == Menu.SelectionResult.Exit) { return returnvalueexit; } else if (sr.Result == Menu.SelectionResult.None) { goto selectionloop; } else if (sr.Result == Menu.SelectionResult.Error) { goto selectionloop; } else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.FirstOrDefault() == null) { goto selectionloop; } - else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.Count() != 2) - { + else if (sr.Result == Menu.SelectionResult.Ok && sr.SelectedParameterList.Count() != 2) + { ColorConsole.WriteLine($"Select exactly 2 DB. Format:FROMLOCALDB,TOREMOTEDB", ConsoleColor.Red); goto selectionloop; } @@ -652,7 +692,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS var spto = sr.SelectedParameterList.ElementAt(1); SQLDataBase dbfrom = spfrom.Parameters as SQLDataBase; SQLDataBase dbto = spto.Parameters as SQLDataBase; - if (!dbto.Xml_IsRemoteDB) + if (!dbto.Xml_IsRemoteDB) { ColorConsole.WriteLine($"TOREMOTEDB '{dbto.SQLCS}' has to be remote!", ConsoleColor.Red); goto selectionloop; @@ -662,64 +702,39 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS ColorConsole.WriteLine($"FROMLOCALDB '{dbfrom.SQLCS}' has to be local!", ConsoleColor.Red); goto selectionloop; } + if (yesorno.ToUpper() != "YES") return (false, false,dbfrom,dbto, null,false); + bool emulation = false; - var selecteddbname = ColorConsole.ReadLine($"Enter the name of the restored DB. EMPTY={dbto.DBName}, EX=exit."); - if (selecteddbname.ToUpper() == "EX") return o; - else if (string.IsNullOrWhiteSpace(selecteddbname)) selecteddbname=dbto.DBName; + if (selecteddbname.ToUpper() == "EX") return returnvalueexit; + else if (string.IsNullOrWhiteSpace(selecteddbname)) selecteddbname = dbto.DBName; confirmloop:; var selection = ColorConsole.ReadLine("Enter CONFIRM to start, EMU to emulate, EX to exit."); - if (selection.ToUpper() == "EX") return o; + if (selection.ToUpper() == "EX") return returnvalueexit; else if (selection.ToUpper() == "EMU") emulation = true; else if (selection.ToUpper() == "CONFIRM") { } else goto confirmloop; - - var DateTimeNow = DateTime.Now; - var usernameList = new string[] { "corplear\\lschwirg", "corplear\\gen_vrhalmadmin", $"corplear\\{Program.ThisComputer.ComputerName}$" }; - foreach (var username in usernameList) - { - ColorConsole.WriteLine(username, ConsoleColor.Yellow, prefix: nameof(SQLDataBaseManagerCore.CreateUser) + ":"); - try { if (!emulation) SQLDataBaseManagerCore.CreateLogin(dbfrom.SQLCS, username, null, "master", LoginType.WindowsUser, loginrolelist); } - catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateLogin)+">>>: "+ex.MessageNested(), ConsoleColor.Red); } - try { if (!emulation) SQLDataBaseManagerCore.CreateUser(dbfrom.SQLCS, username, string.Join(",", fullaccessrolelist), "w"); } - catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateUser) + "\n" + ex.MessageNested(), ConsoleColor.Red); } - } - - //backup dbfrom - var backupfileFullname = SQLDataBaseManagerCore.CreateBackup(dbfrom, false, DateTimeNow,emulation); - //move dbfrom to tranit area - - if (!emulation && !File.Exists(backupfileFullname)) { goto selectionloop; } - - string backupfileFilename = null; - string tranzitfileFullname = null; - try - { - backupfileFilename = Path.GetFileName(backupfileFullname); - tranzitfileFullname = Path.Combine(dbto.Xml_TranzitDirectoryPath, backupfileFilename); - ColorConsole.WriteLine($"Moving backup file {backupfileFullname} to tranzit location: {dbto.Xml_TranzitDirectoryPath}", ConsoleColor.Yellow); - if (!emulation) - { - if (File.Exists(tranzitfileFullname)) { File.Delete(tranzitfileFullname); } - File.Move(backupfileFullname, tranzitfileFullname); - ColorConsole.WriteLine($"...completed...", ConsoleColor.Yellow); - } - } - catch (Exception ex) - { - ColorConsole.WriteLine($"Moving file FAILED!", ConsoleColor.Red); - ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); - goto selectionloop; - } - if (!emulation && !File.Exists(tranzitfileFullname)) { goto selectionloop; } - - //restore backup to dbto - tranzitfileFullname = Path.Combine(dbto.Xml_TranzitDirectoryPath, backupfileFilename); - SQLDataBaseManagerCore.RestoreBackup(dbto, tranzitfileFullname, dbto.Xml_PhysicalFilesDirectoryPath, false, selecteddbname, emulation); - - ColorConsole.WriteLine($"Moving DB to remote server completed. Required time: {(int)(DateTime.Now.Subtract(DateTimeNow).TotalSeconds)} seconds.",ConsoleColor.Green); - return o; + return (false,true,dbfrom,dbto, selecteddbname,emulation); + } + private static (bool,bool) YesOrNo_SetDbOffline(string sqlcs, string dbname) + { + dbname = dbname ?? SQLDataBaseManagerCore.GetDBName(sqlcs); + var servername = SQLDataBaseManagerCore.GetDataSource(sqlcs); + ColorConsole.WriteLine($"Do You want to set database '{dbname}' OFFLINE on server '{servername}'?", ConsoleColor.Yellow); + ColorConsole.WriteLine($" SQL connection string: {sqlcs}", ConsoleColor.Yellow); + ColorConsole.WriteLine($" Server/database: {servername}/{dbname}", ConsoleColor.Yellow); + var yesorno = ColorConsole.ReadLine("Set offline?", ConsoleColor.Yellow, validitylist: new List { "yes", "no" }, defaultvalue: "yes"); + return (yesorno.ToUpper() == "EX", yesorno.ToUpper() == "YES"); + } + private static (bool,bool) YesOrNo_ServerLogin(string sqlcs,string[] usernamelist) + { + ColorConsole.WriteLine($"Do You want to create the following mandatory server logins?", ConsoleColor.Yellow); + ColorConsole.WriteLine($" SQL connection string: {sqlcs}", ConsoleColor.Yellow); + ColorConsole.WriteLine($" Server: {SQLDataBaseManagerCore.GetDataSource(sqlcs)}", ConsoleColor.Yellow); + ColorConsole.WriteLine($" Username list: " + string.Join(",", usernamelist), ConsoleColor.Yellow); + var yesorno = ColorConsole.ReadLine("Create login?", ConsoleColor.Yellow, validitylist: new List { "yes", "no" }, defaultvalue: "yes"); + return (yesorno.ToUpper() == "EX", yesorno.ToUpper() == "YES"); } #endregion MoveDbToRemoteServer @@ -1153,7 +1168,8 @@ GO if (restoredbname.ToUpper() == "EX") { continue; } else if (string.IsNullOrWhiteSpace(restoredbname)) { restoredbname = sqld.DBName; } ColorConsole.WriteLine("Enter the path for the DB physical files.", ConsoleColor.Yellow); - ColorConsole.WriteLine(sqld.PhysicalFilesDirectoryPath, ConsoleColor.Yellow, prefix: $" Empty=current location of source DB: ", bracket: "[]"); + var PhysicalFilesDirectoryPathcolor = sqld.PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + ColorConsole.WriteLine(sqld.PhysicalFilesDirectoryPath, PhysicalFilesDirectoryPathcolor, prefix: $" Empty=current location of source DB: ", bracket: "[]"); ColorConsole.WriteLine(SQLDataBaseManagerCore.GetServerDefaultPhysicalDATFileLocation(sqld.SQLCS)??"???", ConsoleColor.Yellow,prefix: $" DEFAULT= sql server default location.",bracket:"[]"); var targetdirectory = ColorConsole.ReadLine($"Enter the target path.EX=exit.", ConsoleColor.Yellow, suffix: " --> "); if (targetdirectory.ToUpper() == "EX") { continue; } @@ -1224,13 +1240,15 @@ GO } else if (lineix == 3) { - ColorConsole.Write($"{st.PhysicalFilesDirectoryPath}", ConsoleColor.Yellow, prefix: "DB files physical location:", suffix: " "); + var PhysicalFilesDirectoryPathcolor = st.PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + ColorConsole.Write($"{st.PhysicalFilesDirectoryPath}", PhysicalFilesDirectoryPathcolor, prefix: "DB files physical location:", suffix: " "); ColorConsole.WriteLine(" "); return " "; } else if (lineix == 4) { - ColorConsole.Write(st.SizeString, ConsoleColor.Yellow, prefix: "DB size:", suffix: " "); + var SizeStringcolor = st.SizeString.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + ColorConsole.Write(st.SizeString, SizeStringcolor, prefix: "DB size:", suffix: " "); ColorConsole.WriteLine(" "); return " "; } @@ -1253,6 +1271,12 @@ GO #region class SQLDataBaseManager public static class SQLDataBaseManagerCore { + /// + /// Egy adatbázis fizikai file-jainak mozgatása egy másik lokációba + /// + /// + /// + /// public static void RelocatePhysicalFiles(SQLDataBase sqld, string targetdirectory, string restoredbname) { var dbbackupfilepath = CreateBackup(sqld, false,null); @@ -1260,6 +1284,52 @@ GO RestoreBackup(sqld, dbbackupfilepath, targetdirectory, false, restoredbname); if (File.Exists(dbbackupfilepath)) { File.Delete(dbbackupfilepath); } } + + /// + /// Egy adatbázis átmozgatása egy távoli szerverre + /// + /// + /// + /// + /// + /// + public static bool MoveDbToRemoteServer(SQLDataBase dbfrom, SQLDataBase dbto, string selecteddbname, bool emulation) + { + //backup dbfrom + var DateTimeNow = DateTime.Now; + var backupfileFullname = SQLDataBaseManagerCore.CreateBackup(dbfrom, false, DateTimeNow, emulation); + //move dbfrom to tranit area + + if (!emulation && !File.Exists(backupfileFullname)) { return false; } + + string backupfileFilename = null; + string tranzitfileFullname = null; + try + { + backupfileFilename = Path.GetFileName(backupfileFullname); + tranzitfileFullname = Path.Combine(dbto.Xml_TranzitDirectoryPath, backupfileFilename); + ColorConsole.WriteLine($"Moving backup file {backupfileFullname} to tranzit location: {dbto.Xml_TranzitDirectoryPath}", ConsoleColor.Yellow); + if (!emulation) + { + if (File.Exists(tranzitfileFullname)) { File.Delete(tranzitfileFullname); } + File.Move(backupfileFullname, tranzitfileFullname); + ColorConsole.WriteLine($"...completed...", ConsoleColor.Yellow); + } + } + catch (Exception ex) + { + ColorConsole.WriteLine($"Moving file FAILED!", ConsoleColor.Red); + ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); + return false; + } + if (!emulation && !File.Exists(tranzitfileFullname)) { return false; } + + //restore backup to dbto + tranzitfileFullname = Path.Combine(dbto.Xml_TranzitDirectoryPath, backupfileFilename); + SQLDataBaseManagerCore.RestoreBackup(dbto, tranzitfileFullname, dbto.Xml_PhysicalFilesDirectoryPath, false, selecteddbname, emulation); + return true; + } + /// /// Restores database backup (zipped or normal) /// @@ -1316,18 +1386,23 @@ GO smoRestore.PercentCompleteNotification = 1; var backupdevice = new BackupDeviceItem(normalbackupfilepath, DeviceType.File); smoRestore.Devices.Add(backupdevice); - smoRestore.Database = string.IsNullOrWhiteSpace(restoretodbname) - ? smoRestore.ReadBackupHeader(sqlserver).Rows[0]["DatabaseName"].ToString() - : restoretodbname; - + smoRestore.Database = restoretodbname; + if (string.IsNullOrWhiteSpace(smoRestore.Database)) + { + smoRestore.Database = smoRestore.ReadBackupHeader(sqlserver).Rows[0]["DatabaseName"].ToString(); + ColorConsole.WriteLine($"ReadBackupHeader completed. Database name in backup header:{smoRestore.Database}", ConsoleColor.Yellow); + } var dbfilelist = smoRestore.ReadFileList(sqlserver); + ColorConsole.WriteLine($"ReadFileList completed.", ConsoleColor.Yellow); var smorestoreDATfile = new RelocateFile(); string targetdbphysicalfilesdirectorypathDAT = targetdbphysicalfilesdirectorypath; if (string.IsNullOrEmpty(targetdbphysicalfilesdirectorypathDAT)) { targetdbphysicalfilesdirectorypathDAT = sqlserver.DefaultFile; } if (string.IsNullOrEmpty(targetdbphysicalfilesdirectorypathDAT)) { targetdbphysicalfilesdirectorypathDAT = sqlserver.MasterDBPath; } smorestoreDATfile.PhysicalFileName = Path.Combine(targetdbphysicalfilesdirectorypathDAT, smoRestore.Database + "_Data.mdf"); smorestoreDATfile.LogicalFileName = dbfilelist.Select("Type='D'")[0]["LogicalName"].ToString(); + ColorConsole.WriteLine($"DAT PhysicalFileName to relocate: {smorestoreDATfile.PhysicalFileName}", ConsoleColor.Yellow); + ColorConsole.WriteLine($"DAT LogicalFileName to relocate: {smorestoreDATfile.LogicalFileName}", ConsoleColor.Yellow); smoRestore.RelocateFiles.Add(smorestoreDATfile); var smorestoreLOGfile = new RelocateFile(); @@ -1336,6 +1411,8 @@ GO if (string.IsNullOrEmpty(targetdbphysicalfilesdirectorypathLOG)) { targetdbphysicalfilesdirectorypathLOG = sqlserver.MasterDBLogPath; } smorestoreLOGfile.PhysicalFileName = Path.Combine(targetdbphysicalfilesdirectorypathLOG, smoRestore.Database + "_Log.ldf"); smorestoreLOGfile.LogicalFileName = dbfilelist.Select("Type='L'")[0]["LogicalName"].ToString(); + ColorConsole.WriteLine($"LOG PhysicalFileName to relocate: {smorestoreLOGfile.PhysicalFileName}", ConsoleColor.Yellow); + ColorConsole.WriteLine($"LOG LogicalFileName to relocate: {smorestoreLOGfile.LogicalFileName}", ConsoleColor.Yellow); smoRestore.RelocateFiles.Add(smorestoreLOGfile); GetExclusiveUse(smoRestore.Database, sqlserver, sc); @@ -1469,7 +1546,6 @@ GO ColorConsole.Write($"Completed: {e.Percent}%. {e.Message}"); } - #region private methods public static List GetBackupFilePathList(SQLDataBase sqld) { var filenamemask = Path.GetFileNameWithoutExtension(sqld.Xml_BackupFileNameMask); @@ -1619,6 +1695,17 @@ GO } finally { sqlserver?.ConnectionContext.SqlConnectionObject.Dispose(); } } + public static void CreateServerLogins(bool emulation, string sqlcs, string[] usernamelist,string[] loginrolelist, string[] fullaccessrolelist) + { + foreach (var username in usernamelist) + { + ColorConsole.WriteLine(username, ConsoleColor.Yellow, prefix: nameof(SQLDataBaseManagerCore.CreateUser) + ":"); + try { if (!emulation) SQLDataBaseManagerCore.CreateLogin(sqlcs, username, null, "master", LoginType.WindowsUser, loginrolelist); } + catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateLogin) + ">>>: " + ex.MessageNested(), ConsoleColor.Red); } + try { if (!emulation) SQLDataBaseManagerCore.CreateUser(sqlcs, username, string.Join(",", fullaccessrolelist), "w"); } + catch (Exception ex) { ColorConsole.WriteLine(nameof(SQLDataBaseManagerCore.CreateUser) + "\n" + ex.MessageNested(), ConsoleColor.Red); } + } + } public static void ConfigureWindowsUser(string cs, string sapassword, string databasename, string windowsfullusername,string windowsuserpassword,List rolenamelist) { @@ -1699,15 +1786,33 @@ GO } public static void GetExclusiveUse(string databasename,Server sqlserver,SqlConnection sc) { - try { sqlserver.KillAllProcesses(databasename); } + try + { + sqlserver.KillAllProcesses(databasename); + ColorConsole.WriteLine($"{nameof(GetExclusiveUse)}/KillAllProcesses completed.", ConsoleColor.Yellow); + } catch (Exception ex) { ColorConsole.WriteLine($"{nameof(GetExclusiveUse)}/{nameof(Server.KillAllProcesses)}>>>:" + ex.MessageNested(), ConsoleColor.Red); } SqlCommand sqlcommand = null; - try { sqlcommand = new SqlCommand($"ALTER DATABASE {databasename} SET Single_User WITH Rollback IMMEDIATE", sc); sqlcommand.ExecuteNonQuery(); } + try + { + var cmd = $"ALTER DATABASE {databasename} SET Single_User WITH Rollback IMMEDIATE"; + sqlcommand = new SqlCommand(cmd, sc); sqlcommand.ExecuteNonQuery(); + ColorConsole.WriteLine($"{nameof(GetExclusiveUse)}/{nameof(SqlCommand.ExecuteNonQuery)}/\"{cmd}\" completed.", ConsoleColor.Yellow); + } catch (Exception ex) { ColorConsole.WriteLine($"{nameof(GetExclusiveUse)}/{nameof(SqlCommand.ExecuteNonQuery)}>>>: " + ex.MessageNested(), ConsoleColor.Red); } finally { sqlcommand?.Dispose(); } } + public static void SetDatabaseOffline(string sqlcs, string dbname=null) + { + dbname = dbname ?? SQLDataBaseManagerCore.GetDBName(sqlcs); + var sc = ServerConnectionPool.GetSqlConnection(sqlcs, "master"); + var cmd = $"ALTER DATABASE {dbname} SET OFFLINE WITH ROLLBACK IMMEDIATE"; + //var cmd = $"ALTER DATABASE {dbname ?? SQLDataBaseManagerCore.GetDBName(sqlcs)} SET ONLINE"; + var sqlcommand = new SqlCommand(cmd, sc); sqlcommand.ExecuteNonQuery(); + } + public static string GetServerDefaultPhysicalDATFileLocation(string cs) { Server sqlserver = null; @@ -2186,7 +2291,6 @@ GO } } #endregion BackupSqlData - #endregion private methods } #endregion class SQLDataBaseManager @@ -2263,7 +2367,7 @@ GO try { GetPhysicalFilesLocationAndSize(this.SQLCS, out this.SizeString, out this.PhysicalFilesDirectoryPath); - this.Status = this.PhysicalFilesDirectoryPath=="ERR" ? SQLDBStatus.NoAccess : SQLDBStatus.OK; + this.Status = this.PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK; this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS); this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); } @@ -2305,7 +2409,7 @@ GO } dbsizetext = dbsizetext ?? "N/A"; } - catch { } + catch (Exception ex) {dbsizetext = $"ERROR! {nameof(GetPhysicalFilesLocationAndSize)} getting size." + ex.MessageNested() + $" sqlconnectionstring:{sqlconnectionstring}";} try { @@ -2322,10 +2426,14 @@ GO var result = SQLDataBaseManagerCore.ExecuteSQLScript(sqlc, scripttext, commandtimeout, vars); if (result.ReturnValue != 0) { dbpathtext = Path.GetDirectoryName(result.ReturnMessage); } } - catch { } + catch (Exception ex) {dbpathtext =$"ERROR! {nameof(GetPhysicalFilesLocationAndSize)} getting location." + ex.MessageNested() + $" sqlconnectionstring:{sqlconnectionstring}";} sqlc.Close(); } - catch { } + catch (Exception ex) + { + dbpathtext = $"ERROR! {nameof(GetPhysicalFilesLocationAndSize)}." + ex.MessageNested() + $" sqlconnectionstring:{sqlconnectionstring}"; + dbsizetext = null; + } dbsizetext = dbsizetext ?? "ERR"; dbpathtext = dbpathtext ?? "ERR"; } diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index 8f952c8..beb8e64 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.29.1.0")] -[assembly: AssemblyFileVersion("1.29.1.0")] +[assembly: AssemblyVersion("1.29.2.0")] +[assembly: AssemblyFileVersion("1.29.2.0")] -- libgit2 0.21.2