diff --git a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs index 1759744..d09eb51 100644 --- a/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs +++ b/Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs @@ -112,7 +112,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS SQLDataBase sqld = p.Parameters as SQLDataBase; try { - SQLDataBaseManagerCore.BackupSqlData(sqld,TS); + if (FunctionIsNotAvailable(sqld)) { return o; } + SQLDataBaseManagerCore.BackupSqlData(sqld,TS); ColorConsole.WriteLine($"SQLDB data scripts created. Name:{sqld.Xml_Description}", ConsoleColor.Green); } catch (Exception ex){ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red);} @@ -141,7 +142,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS SQLDataBase sqld = p.Parameters as SQLDataBase; try { - SQLDataBaseManagerCore.BackupSqlScripts(sqld,TS); + if (FunctionIsNotAvailable(sqld)) { return o; } + SQLDataBaseManagerCore.BackupSqlScripts(sqld,TS); ColorConsole.WriteLine($"SQLDB code scripts created. Name:{sqld.Xml_Description}", ConsoleColor.Green); } catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); } @@ -167,17 +169,24 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS var TS = DateTime.Now; foreach (var p in sr.SelectedParameterList) { - SQLDataBase ssqldb = p.Parameters as SQLDataBase; + SQLDataBase sqld = p.Parameters as SQLDataBase; try { - SQLDataBaseManagerCore.CreateBackup(ssqldb,null,TS); - ColorConsole.WriteLine($"Database backup created. Name:{ssqldb.DBName}", ConsoleColor.Green); + if (FunctionIsNotAvailable(sqld)) { return o; } + SQLDataBaseManagerCore.CreateBackup(sqld,null,TS); + ColorConsole.WriteLine($"Database backup created. Name:{sqld.DBName}", ConsoleColor.Green); } catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); } } return o; } - private static object RestoreDataBase(object parameter, object o) + private static bool FunctionIsNotAvailable(SQLDataBase ssqldb) + { + const string FUNNOTAVAILTXT = "Function is not available for server connection strings wit no DB name specified!"; + if (string.IsNullOrWhiteSpace(SQLDataBaseManagerCore.GetDBName(ssqldb.SQLCS))) { ColorConsole.WriteLine(FUNNOTAVAILTXT, ConsoleColor.Red); return true; } + return false; + } + private static object RestoreDataBase(object parameter, object o) { var config = (parameter as Menu.ExecutorParameter).GetConfig(); var args = (parameter as Menu.ExecutorParameter).Args; @@ -196,13 +205,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS else if (sr.Result == Menu.SelectionResult.Ok) { } else { } var p = sr.SelectedParameterList.First(); - SQLDataBase st = p.Parameters as SQLDataBase; + SQLDataBase sqld = p.Parameters as SQLDataBase; try { - var targetdirectorypath = st.Xml_PhysicalFilesDirectoryPath; - var targetdbname = st.DBName; - bool restorefromzip = st.Xml_CreateZip; - var backupfilelist = SQLDataBaseManagerCore.GetBackupFilePathList(st); + if (FunctionIsNotAvailable(sqld)) { return o; } + var targetdirectorypath = sqld.Xml_PhysicalFilesDirectoryPath; + var targetdbname = sqld.DBName; + bool restorefromzip = sqld.Xml_CreateZip; + var backupfilelist = SQLDataBaseManagerCore.GetBackupFilePathList(sqld); Dictionary selectionlist = new Dictionary(); string selectedbackupfilepath=null; @@ -214,7 +224,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS .Select(x => new KeyValuePair($"{x.Name}({x.Length}bytes,created:{x.CreationTime})", x.FullName)) .ToDictionary(x => x.Key, x => x.Value); selectionlist.Add("*", "other..."); - var ms = Menu.SelectFromItemList($"Backup files of {st.DBName}", "Select the backup file to restore! First is the newest!", selectionlist, Menu.SelectionMode.Single, getconfirmation: true); + var ms = Menu.SelectFromItemList($"Backup files of {sqld.DBName}", "Select the backup file to restore! First is the newest!", selectionlist, Menu.SelectionMode.Single, getconfirmation: true); if (ms == null) { goto startselection; } else if (ms.SelectedKeyList.First() == "*") { } else { selectedbackupfilepath = ms.SelectedParameterList.First().Parameters.ToString(); } @@ -227,8 +237,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS else if (string.IsNullOrWhiteSpace(selectedbackupfilepath)) goto enterpathtobackupfileloop; } - SQLDataBaseManagerCore.RestoreBackup(st, selectedbackupfilepath, targetdirectorypath, restorefromzip, targetdbname); - ColorConsole.WriteLine($"Database '{st.DBName}' restored to '{targetdbname}' into directory '{targetdirectorypath}'.", ConsoleColor.Green); + SQLDataBaseManagerCore.RestoreBackup(sqld, 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); } return o; @@ -495,8 +505,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS var p = sr.SelectedParameterList.FirstOrDefault(); SQLDataBase sqld = p.Parameters as SQLDataBase; + if (FunctionIsNotAvailable(sqld)) { return o; } - getparametersloop: + getparametersloop: List DbusrToExecuteList = new List(); string selecteddbusrkey = null; if (sqld.Xml_SQLDbUserList.Count == 0) @@ -645,7 +656,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS var DateTimeNow = DateTime.Now; movedbanswer = YesOrNo_MoveDbToRemoteServer(config, selectedsqldbindexes); - if (movedbanswer.Exit) break; + if (FunctionIsNotAvailable(movedbanswer.Dbfrom)) { continue; } + if (FunctionIsNotAvailable(movedbanswer.Dbto)) { continue; } + if (movedbanswer.Exit) break; if (movedbanswer.Yes) { var movesuccess = SQLDataBaseManagerCore.MoveDbToRemoteServer(movedbanswer.Dbfrom, movedbanswer.Dbto, movedbanswer.Selecteddbname, movedbanswer.Emulation); @@ -814,8 +827,9 @@ GO var p = sr.SelectedParameterList.FirstOrDefault(); if (p == null) { return o; } SQLDataBase sqld = p.Parameters as SQLDataBase; + if (FunctionIsNotAvailable(sqld)) { return o; } - getparametersloop:; + getparametersloop:; List TriggerToExecuteList = new List(); string selectedtrgkey =null; @@ -1015,7 +1029,7 @@ GO bool multirunmode = !string.IsNullOrWhiteSpace(ss.MultirunParameters); int commandtimeout = ss.CommandTimeout; ReturnInfoJSON result = null; - using (var sqlc = ServerConnectionPool.GetSqlConnection(sqld.SQLCS, open: true)) + using (var sqlc = ServerConnectionPool.GetSqlConnection(ss.SQLCS, open: true)) { if (multirunmode) { result = SQLDataBaseManagerCore.ExecuteMultirunSQLScript(sqlc, ss, ExitAtThisPoint); } else @@ -1085,7 +1099,8 @@ GO SQLDataBase sqld = p.Parameters as SQLDataBase; try { - ColorConsole.WriteLine(prefix: $"Enter the userid/password (for the user in favour you want to drop the DB). Format:", bracket: "()", text: "[USERID[,PASSWORD]]:", f: ConsoleColor.Yellow); + if (FunctionIsNotAvailable(sqld)) { return o; } + ColorConsole.WriteLine(prefix: $"Enter the userid/password (for the user in favour you want to drop the DB). Format:", bracket: "()", text: "[USERID[,PASSWORD]]:", f: ConsoleColor.Yellow); ColorConsole.WriteLine(prefix: " ", text: "[USERID,PASSWORD empty]", bracket: "[]", suffix: $":use windows authentication with current user", f: ConsoleColor.Yellow); ColorConsole.WriteLine(prefix: " ", text: "USERID", bracket: "[]", suffix: $":use windows authentication with this user", f: ConsoleColor.Yellow); ColorConsole.WriteLine(prefix: " ", text: "USERID,PASSWORD", bracket: "[]", suffix: $":use sql server authentication with this user and password.", f: ConsoleColor.Yellow); @@ -1170,7 +1185,8 @@ GO SQLDataBase sqld = p.Parameters as SQLDataBase; try { - ColorConsole.WriteLine(prefix: $"Enter the shrink options. Format:", bracket:"()", text:"OPTION,FreeSpacePercent:", f:ConsoleColor.Yellow); + if (FunctionIsNotAvailable(sqld)) { return o; } + ColorConsole.WriteLine(prefix: $"Enter the shrink options. Format:", bracket:"()", text:"OPTION,FreeSpacePercent:", f:ConsoleColor.Yellow); ColorConsole.WriteLine(prefix:" ", text:"Default", bracket: "[]", suffix: $": (default) compacts the data and removes free space from the DB. Use togethere with FreeSpacePercent.", f:ConsoleColor.Yellow); ColorConsole.WriteLine(prefix: " ", text: "NoTruncate",bracket:"[]", suffix: $": compacts the data, but does not remove free space from the DB. FreeSpacePercent is not applicable.", f: ConsoleColor.Yellow); ColorConsole.WriteLine(prefix: " ", text: "TruncateOnly", bracket: "[]", suffix: $": does not compact the data, but removes free space from the DB. Use togethere with FreeSpacePercent.", f: ConsoleColor.Yellow); @@ -1213,7 +1229,8 @@ GO SQLDataBase sqld = p.Parameters as SQLDataBase; try { - var restoredbname = ColorConsole.ReadLine($"Enter the name of the DB to copy '{sqld.DBName}' to. Empty={sqld.DBName}. EX=exit.", ConsoleColor.Yellow, suffix: " --> "); + if (FunctionIsNotAvailable(sqld)) { return o; } + var restoredbname = ColorConsole.ReadLine($"Enter the name of the DB to copy '{sqld.DBName}' to. Empty={sqld.DBName}. EX=exit.", ConsoleColor.Yellow, suffix: " --> "); 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); @@ -1266,7 +1283,7 @@ GO ColorConsole.Write($"{st.Xml_Description}", ConsoleColor.Black, ConsoleColor.White); var statuscolor = st.Status == SQLDataBase.SQLDBStatus.NoAccess ? ConsoleColor.Red:ConsoleColor.Green; ColorConsole.Write(st.Status.ToString(), statuscolor, bracket: "[]", prefix: " ", suffix: ". "); - ColorConsole.Write(st.DBName, statuscolor, bracket: "[]", prefix: "Database ", 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) { @@ -1277,7 +1294,8 @@ GO } else if (lineix == 1) { - ColorConsole.Write($"{st.Xml_BackupFileNameMask}", ConsoleColor.Yellow, prefix: "Backup to:", suffix: ".xxx"); + if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + ColorConsole.Write($"{st.Xml_BackupFileNameMask}", ConsoleColor.Yellow, prefix: "Backup to:", suffix: ".xxx"); ColorConsole.WriteLine(); return Menu.MenuItemDisplayerReturnValue.NEXTLINE; } @@ -1289,14 +1307,16 @@ GO } else if (lineix == 3) { - var PhysicalFilesDirectoryPathcolor = st.PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; + var PhysicalFilesDirectoryPathcolor = st.PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; ColorConsole.Write($"{st.PhysicalFilesDirectoryPath}", PhysicalFilesDirectoryPathcolor, prefix: "DB files physical location:", suffix: " "); ColorConsole.WriteLine(" "); return Menu.MenuItemDisplayerReturnValue.NEXTLINE; } else if (lineix == 4) { - var SizeStringcolor = st.SizeString.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; + 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; @@ -1307,7 +1327,8 @@ GO if (st.Xml_SQLScriptList.Count-1 < lineix-5) { return Menu.MenuItemDisplayerReturnValue.EXIT; } var s = st.Xml_SQLScriptList.ToArray()[lineix-5]; ColorConsole.Write(s.Key, ConsoleColor.Yellow, bracket: "[]", suffix: " ", prefix: " Script: "); - ColorConsole.WriteLine($"{s.Description} ({s.Name})", ConsoleColor.Yellow); + ColorConsole.Write(s.Name, ConsoleColor.Yellow, bracket: "[]", suffix: " "); + ColorConsole.WriteLine(s.Description, ConsoleColor.White); return Menu.MenuItemDisplayerReturnValue.NEXTLINE; } return Menu.MenuItemDisplayerReturnValue.EXIT; @@ -1981,18 +2002,18 @@ GO /// /// - public static ReturnInfoJSON ExecuteMultirunSQLScript(SqlConnection sqlc, SQLDataBase.SQLScript sqlscript, Func ExitAtThisPoint=null) + public static ReturnInfoJSON ExecuteMultirunSQLScript(SqlConnection sqlc,SQLDataBase.SQLScript sqlscript, Func ExitAtThisPoint=null) { - ReturnInfoJSON ret1=null; - string sqltxt = null; - int? getdbnumofrowsresult=null; - DateTime? getdbmindateresult=null; + ReturnInfoJSON ret1 = null; + string sqltxt = null; + int? getdbnumofrowsresult = null; + DateTime? getdbmindateresult = null; var multirunresult = new List>(); var scriptparameterkvplist = (new Tools.KvpString(sqlscript.ScriptParameters)).ResolveInteractive(); - string sqltxtalmostresolved = scriptparameterkvplist.Substitute(sqlscript.ScriptText); //parameters of the run are still unresolved - if (sqltxtalmostresolved == null) {return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE));} //won't really get, but we never know... + string sqltxtalmostresolved = scriptparameterkvplist.Substitute(sqlscript.ScriptText); //parameters of the run are still unresolved + if (sqltxtalmostresolved == null) { return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE)); } //won't really get, but we never know... //get number of total records in the database getdbnumofrowsresult = GetDBNumofRows(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); @@ -2003,27 +2024,27 @@ GO getdbmindateresult = GetDBMindate(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); if (getdbmindateresult == null) return Finalize(1, multirunresult); DateTime mindateTS_before = getdbmindateresult.Value; - var _multirunresult = multirunresult.Select(kvp => new KeyValuePair(kvp.Key, kvp.Value)).ToList(); + var _multirunresult = multirunresult.Select(kvp => new KeyValuePair(kvp.Key, kvp.Value)).ToList(); Add(_multirunresult, $"DBRECORDS", $"{numoftotaldbrecords_before}"); Add(_multirunresult, $"MINDATE", $"{mindateTS_before}"); - var exithere = (ExitAtThisPoint?.Invoke(Finalize(0, _multirunresult),null)) ?? false; + var exithere = (ExitAtThisPoint?.Invoke(Finalize(0, _multirunresult), null)) ?? false; if (exithere) { Add(_multirunresult, $"Exit requested by user"); return Finalize(0, _multirunresult); } var multirunparameterskvplist = (new Tools.KvpString(sqlscript.MultirunParameters)).ResolveInteractive(); - if(multirunparameterskvplist == null) { return Finalize(0, Add(multirunresult, ERRMSG_NOMULTIRUNPARAMETERS)); } //user exit with selecting EX - var smrp = SetMultirunParameters(multirunparameterskvplist, multirunresult); - if (smrp == null) { return Finalize(1, multirunresult);} - (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns) = smrp.Value; + if (multirunparameterskvplist == null) { return Finalize(0, Add(multirunresult, ERRMSG_NOMULTIRUNPARAMETERS)); } //user exit with selecting EX + var smrp = SetMultirunParameters(multirunparameterskvplist, multirunresult); + if (smrp == null) { return Finalize(1, multirunresult); } + (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns) = smrp.Value; try { - DateTime starttime = DateTime.Now; + DateTime starttime = DateTime.Now; var limitdatefornextrun = mindateTS_before; int exceptioncounter = 0; - const int MAXEXCEPTIONS = 3; //after this number of subsequent exceptions we exit - int deleteruncounter = 0; - int runresult; + const int MAXEXCEPTIONS = 3; //after this number of subsequent exceptions we exit + int deleteruncounter = 0; + int runresult; while (true) { if (limitdatefornextrun >= par_limitdate) break; @@ -2031,36 +2052,36 @@ GO var loople = new List>(); if (limitdatefornextrun > par_limitdate) limitdatefornextrun = par_limitdate; Add(loople, $"RUN#{deleteruncounter}"); - try - { - sqltxt = Tools.KvpString.Substitute($"{RUNNINGMODE}={RUNNINGMODE_ONERUN};{RUNNINGMODE_ONERUN_PARAMETER_DELETEBEFOREDATE}={limitdatefornextrun:s};", sqltxtalmostresolved); - if (sqltxt == null) { return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE)); } //won't really get, but we never know... - ret1 = ExecuteSQLScript(sqlc, sqltxt, sqlscript.CommandTimeout, null); - Add(loople, $"LIMITDATE", limitdatefornextrun.ToString()); - Add(loople, $"RETCODE", ret1.ReturnValue.ToString()); - Add(loople, $"RETMSG", ret1.ReturnMessage); - - deleteruncounter++; - exceptioncounter = 0; - runresult = 0; + try + { + sqltxt = Tools.KvpString.Substitute($"{RUNNINGMODE}={RUNNINGMODE_ONERUN};{RUNNINGMODE_ONERUN_PARAMETER_DELETEBEFOREDATE}={limitdatefornextrun:s};", sqltxtalmostresolved); + if (sqltxt == null) { return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE)); } //won't really get, but we never know... + ret1 = ExecuteSQLScript(sqlc, sqltxt, sqlscript.CommandTimeout, null); + Add(loople, $"LIMITDATE", limitdatefornextrun.ToString()); + Add(loople, $"RETCODE", ret1.ReturnValue.ToString()); + Add(loople, $"RETMSG", ret1.ReturnMessage); + + deleteruncounter++; + exceptioncounter = 0; + runresult = 0; } - catch (Exception ex) - { - exceptioncounter++; - string errmsg = ""; while (ex != null) { errmsg += ex.Message; ex = ex.InnerException; } - Add(loople, $"EXCEPTION RESULT DeleteRun", errmsg); + catch (Exception ex) + { + exceptioncounter++; + string errmsg = ""; while (ex != null) { errmsg += ex.Message; ex = ex.InnerException; } + Add(loople, $"EXCEPTION RESULT DeleteRun", errmsg); runresult = 1; if (exceptioncounter > MAXEXCEPTIONS) { return Finalize(1, multirunresult); } } - var exitfromloop = (ExitAtThisPoint?.Invoke(Finalize(runresult, loople),new TimeSpan(0,0,5))) ?? false; + var exitfromloop = (ExitAtThisPoint?.Invoke(Finalize(runresult, loople), new TimeSpan(0, 0, 5))) ?? false; if (exitfromloop) { Add(multirunresult, $"Exit requested by user"); break; } Thread.Sleep((int)(par_delaybetweenruns.TotalMilliseconds)); } //get minimum date in the database - getdbmindateresult = GetDBMindate(sqltxtalmostresolved,multirunresult, sqlscript.CommandTimeout,sqlc); - if (getdbmindateresult==null) return Finalize(1, multirunresult); - DateTime mindateTS_after = getdbmindateresult.Value; + getdbmindateresult = GetDBMindate(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); + if (getdbmindateresult == null) return Finalize(1, multirunresult); + DateTime mindateTS_after = getdbmindateresult.Value; //get number of total records in the database getdbnumofrowsresult = GetDBNumofRows(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); @@ -2075,7 +2096,7 @@ GO } catch (Exception ex) { return Finalize(1, Add(multirunresult, ex)); } } - private static (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns)? SetMultirunParameters(Tools.KvpString argkvplist,List> multirunresult) + private static (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns)? SetMultirunParameters(Tools.KvpString argkvplist,List> multirunresult) { bool par_testmode; int par_limitdays; @@ -2628,11 +2649,22 @@ GO { try { - GetPhysicalFilesLocationAndSize(this.SQLCS, out this.SizeString, out this.PhysicalFilesDirectoryPath); - this.Status = this.PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK; - this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS); - this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); - } + string dbname = SQLDataBaseManagerCore.GetDBName(this.SQLCS); + if (string.IsNullOrWhiteSpace(dbname)) + { + var sqlc = ServerConnectionPool.GetSqlConnection(this.SQLCS, open: true); + this.Status = SQLDBStatus.OK; + this.DBName = ""; + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); + } + else + { + GetPhysicalFilesLocationAndSize(this.SQLCS, out this.SizeString, out this.PhysicalFilesDirectoryPath); + this.Status = this.PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK; + this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS); + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); + } + } catch { this.Status = SQLDBStatus.NoAccess; @@ -2725,7 +2757,8 @@ GO Xml_BackupTimeout = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.BackupTimeout), sqldatabasexml, common.Xml_BackupTimeout); Xml_SQLDataList = new List(); - var sqldataXmlList = GetAllXElements(sqldatabasexml, nameof(XmlStructure.SQLDataBase.SQLData)); + IEnumerable sqldataXmlList=null; + try { sqldataXmlList = GetAllXElements(sqldatabasexml, nameof(XmlStructure.SQLDataBase.SQLData)); } catch { } if (sqldataXmlList!=null) { foreach (var sqldataXml in sqldataXmlList) { Xml_SQLDataList.Add(new SQLData(sqldataXml)); } } Xml_SQLLastUpdatedTriggerList = new List(); @@ -2746,7 +2779,7 @@ GO Xml_SQLScriptList = new List(); var sqlscriptsXml = GetXElement(sqldatabasexml, nameof(XmlStructure.SQLDataBase.Scripts)); var sqlscriptXmlList = GetAllXElements(sqlscriptsXml, nameof(XmlStructure.SQLDataBase.Scripts.Script)); - if (sqlscriptXmlList != null) { int scriptindex = 1; foreach (var sqlscriptXml in sqlscriptXmlList) { Xml_SQLScriptList.Add(new SQLScript(sqlscriptXml, Xml_ScriptCommandTimeout,scriptindex++)); } } + if (sqlscriptXmlList != null) { int scriptindex = 1; foreach (var sqlscriptXml in sqlscriptXmlList) { Xml_SQLScriptList.Add(new SQLScript(sqlscriptXml, Xml_SQLConnectionString,Xml_ScriptCommandTimeout, scriptindex++)); } } } #endregion xml constructor #region cloner constructor @@ -2857,8 +2890,9 @@ GO public static class ScriptCommandTimeout { public static class Values { public const int DEFAULT = 10000; } } public static class Parameters { public static class Values { public const string DEFAULT = ""; } } public static class Multirun { public static class Values { public const string DEFAULT = ""; } } - } - } + public static class SQLConnectionString { public static class Values { public const string DEFAULT = null; } } + } + } } } } @@ -2874,10 +2908,15 @@ GO public int CommandTimeout = 10000; public string ScriptParameters=null; public string MultirunParameters=null; + public string SQLConnectionString=null; + public string SQLCS + { + get { return XmlProcessing.ConnectionStringStore.GetSQL(this.SQLConnectionString); } + } - public SQLScript() { } + public SQLScript() { } public SQLScript(SQLScript sqls) { Name = sqls.Name; Description = sqls.Description; ScriptText= sqls.ScriptText; } - public SQLScript(XElement sqlscriptXml, int defaultcommandtimeout, int index) + public SQLScript(XElement sqlscriptXml,string sqlconnectionstring, int defaultcommandtimeout, int index) { ScriptParameters = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters.Values.DEFAULT); MultirunParameters= GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Multirun), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Multirun.Values.DEFAULT); @@ -2886,6 +2925,8 @@ GO Name = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Name), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Name.Values.DEFAULT); FilePath = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.File), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.File.Values.DEFAULT); Description= GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Description), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Description.Values.DEFAULT); + SQLConnectionString = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.SQLConnectionString), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.SQLConnectionString.Values.DEFAULT); + if (SQLConnectionString == null) SQLConnectionString = sqlconnectionstring; Tools.KvpString.Resolve(ScriptParameters, this.Name, out this.Name, disableinteractive: true); Tools.KvpString.Resolve(ScriptParameters, this.Description, out this.Description, disableinteractive: true); @@ -3033,16 +3074,16 @@ GO } public static void Open(SqlConnection sqlc) { - if (IsMasterInacessible(sqlc) || IsInacessible(sqlc)) - { - throw new Exception($"DB {sqlc.Database} on server {sqlc.DataSource} is inaccessible!"); - } - try { sqlc.Open(); } - catch (Exception ex) + if (IsMasterInacessible(sqlc) || IsInacessible(sqlc)) { throw new Exception($"SQL server {sqlc.DataSource} is inaccessible!"); } + if (!string.IsNullOrWhiteSpace(sqlc.Database)) { - MarkMasterInacessible(sqlc); - MarkInacessible(sqlc); - throw ex; + try { sqlc.Open(); } + catch (Exception ex) + { + MarkMasterInacessible(sqlc); + MarkInacessible(sqlc); + throw ex; + } } } private static bool IsMasterDBConnected(SqlConnection sqlc) diff --git a/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs b/Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs index 29842f6..eca01a1 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.31.2.0")] -[assembly: AssemblyFileVersion("1.31.2.0")] +[assembly: AssemblyVersion("1.31.3.0")] +[assembly: AssemblyFileVersion("1.31.3.0")] -- libgit2 0.21.2