Commit 1ff12b69628093373f0183c7fbae12dc136abbe4
1 parent
f450c758
v1.31.3.0
- Scriptek kezelésének módosítása - DB név nélküli connectionstringek kezelése
Showing
2 changed files
with
128 additions
and
87 deletions
Show diff stats
Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
... | ... | @@ -112,7 +112,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
112 | 112 | SQLDataBase sqld = p.Parameters as SQLDataBase; |
113 | 113 | try |
114 | 114 | { |
115 | - SQLDataBaseManagerCore.BackupSqlData(sqld,TS); | |
115 | + if (FunctionIsNotAvailable(sqld)) { return o; } | |
116 | + SQLDataBaseManagerCore.BackupSqlData(sqld,TS); | |
116 | 117 | ColorConsole.WriteLine($"SQLDB data scripts created. Name:{sqld.Xml_Description}", ConsoleColor.Green); |
117 | 118 | } |
118 | 119 | catch (Exception ex){ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red);} |
... | ... | @@ -141,7 +142,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
141 | 142 | SQLDataBase sqld = p.Parameters as SQLDataBase; |
142 | 143 | try |
143 | 144 | { |
144 | - SQLDataBaseManagerCore.BackupSqlScripts(sqld,TS); | |
145 | + if (FunctionIsNotAvailable(sqld)) { return o; } | |
146 | + SQLDataBaseManagerCore.BackupSqlScripts(sqld,TS); | |
145 | 147 | ColorConsole.WriteLine($"SQLDB code scripts created. Name:{sqld.Xml_Description}", ConsoleColor.Green); |
146 | 148 | } |
147 | 149 | catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); } |
... | ... | @@ -167,17 +169,24 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
167 | 169 | var TS = DateTime.Now; |
168 | 170 | foreach (var p in sr.SelectedParameterList) |
169 | 171 | { |
170 | - SQLDataBase ssqldb = p.Parameters as SQLDataBase; | |
172 | + SQLDataBase sqld = p.Parameters as SQLDataBase; | |
171 | 173 | try |
172 | 174 | { |
173 | - SQLDataBaseManagerCore.CreateBackup(ssqldb,null,TS); | |
174 | - ColorConsole.WriteLine($"Database backup created. Name:{ssqldb.DBName}", ConsoleColor.Green); | |
175 | + if (FunctionIsNotAvailable(sqld)) { return o; } | |
176 | + SQLDataBaseManagerCore.CreateBackup(sqld,null,TS); | |
177 | + ColorConsole.WriteLine($"Database backup created. Name:{sqld.DBName}", ConsoleColor.Green); | |
175 | 178 | } |
176 | 179 | catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); } |
177 | 180 | } |
178 | 181 | return o; |
179 | 182 | } |
180 | - private static object RestoreDataBase(object parameter, object o) | |
183 | + private static bool FunctionIsNotAvailable(SQLDataBase ssqldb) | |
184 | + { | |
185 | + const string FUNNOTAVAILTXT = "Function is not available for server connection strings wit no DB name specified!"; | |
186 | + if (string.IsNullOrWhiteSpace(SQLDataBaseManagerCore.GetDBName(ssqldb.SQLCS))) { ColorConsole.WriteLine(FUNNOTAVAILTXT, ConsoleColor.Red); return true; } | |
187 | + return false; | |
188 | + } | |
189 | + private static object RestoreDataBase(object parameter, object o) | |
181 | 190 | { |
182 | 191 | var config = (parameter as Menu.ExecutorParameter).GetConfig<SQLDataBaseManagerXmlProcessor>(); |
183 | 192 | var args = (parameter as Menu.ExecutorParameter).Args; |
... | ... | @@ -196,13 +205,14 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
196 | 205 | else if (sr.Result == Menu.SelectionResult.Ok) { } |
197 | 206 | else { } |
198 | 207 | var p = sr.SelectedParameterList.First(); |
199 | - SQLDataBase st = p.Parameters as SQLDataBase; | |
208 | + SQLDataBase sqld = p.Parameters as SQLDataBase; | |
200 | 209 | try |
201 | 210 | { |
202 | - var targetdirectorypath = st.Xml_PhysicalFilesDirectoryPath; | |
203 | - var targetdbname = st.DBName; | |
204 | - bool restorefromzip = st.Xml_CreateZip; | |
205 | - var backupfilelist = SQLDataBaseManagerCore.GetBackupFilePathList(st); | |
211 | + if (FunctionIsNotAvailable(sqld)) { return o; } | |
212 | + var targetdirectorypath = sqld.Xml_PhysicalFilesDirectoryPath; | |
213 | + var targetdbname = sqld.DBName; | |
214 | + bool restorefromzip = sqld.Xml_CreateZip; | |
215 | + var backupfilelist = SQLDataBaseManagerCore.GetBackupFilePathList(sqld); | |
206 | 216 | Dictionary<string, string> selectionlist = new Dictionary<string, string>(); |
207 | 217 | |
208 | 218 | string selectedbackupfilepath=null; |
... | ... | @@ -214,7 +224,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
214 | 224 | .Select(x => new KeyValuePair<string, string>($"{x.Name}({x.Length}bytes,created:{x.CreationTime})", x.FullName)) |
215 | 225 | .ToDictionary(x => x.Key, x => x.Value); |
216 | 226 | selectionlist.Add("*", "other..."); |
217 | - 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); | |
227 | + 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); | |
218 | 228 | if (ms == null) { goto startselection; } |
219 | 229 | else if (ms.SelectedKeyList.First() == "*") { } |
220 | 230 | else { selectedbackupfilepath = ms.SelectedParameterList.First().Parameters.ToString(); } |
... | ... | @@ -227,8 +237,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
227 | 237 | else if (string.IsNullOrWhiteSpace(selectedbackupfilepath)) goto enterpathtobackupfileloop; |
228 | 238 | } |
229 | 239 | |
230 | - SQLDataBaseManagerCore.RestoreBackup(st, selectedbackupfilepath, targetdirectorypath, restorefromzip, targetdbname); | |
231 | - ColorConsole.WriteLine($"Database '{st.DBName}' restored to '{targetdbname}' into directory '{targetdirectorypath}'.", ConsoleColor.Green); | |
240 | + SQLDataBaseManagerCore.RestoreBackup(sqld, selectedbackupfilepath, targetdirectorypath, restorefromzip, targetdbname); | |
241 | + ColorConsole.WriteLine($"Database '{sqld.DBName}' restored to '{targetdbname}' into directory '{targetdirectorypath}'.", ConsoleColor.Green); | |
232 | 242 | } |
233 | 243 | catch (Exception ex) { ColorConsole.WriteLine(ex.MessageNested(), ConsoleColor.Red); } |
234 | 244 | return o; |
... | ... | @@ -495,8 +505,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
495 | 505 | |
496 | 506 | var p = sr.SelectedParameterList.FirstOrDefault(); |
497 | 507 | SQLDataBase sqld = p.Parameters as SQLDataBase; |
508 | + if (FunctionIsNotAvailable(sqld)) { return o; } | |
498 | 509 | |
499 | - getparametersloop: | |
510 | + getparametersloop: | |
500 | 511 | List<SQLDataBase.DBUser> DbusrToExecuteList = new List<SQLDataBase.DBUser>(); |
501 | 512 | string selecteddbusrkey = null; |
502 | 513 | if (sqld.Xml_SQLDbUserList.Count == 0) |
... | ... | @@ -645,7 +656,9 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS |
645 | 656 | var DateTimeNow = DateTime.Now; |
646 | 657 | |
647 | 658 | movedbanswer = YesOrNo_MoveDbToRemoteServer(config, selectedsqldbindexes); |
648 | - if (movedbanswer.Exit) break; | |
659 | + if (FunctionIsNotAvailable(movedbanswer.Dbfrom)) { continue; } | |
660 | + if (FunctionIsNotAvailable(movedbanswer.Dbto)) { continue; } | |
661 | + if (movedbanswer.Exit) break; | |
649 | 662 | if (movedbanswer.Yes) |
650 | 663 | { |
651 | 664 | var movesuccess = SQLDataBaseManagerCore.MoveDbToRemoteServer(movedbanswer.Dbfrom, movedbanswer.Dbto, movedbanswer.Selecteddbname, movedbanswer.Emulation); |
... | ... | @@ -814,8 +827,9 @@ GO |
814 | 827 | var p = sr.SelectedParameterList.FirstOrDefault(); |
815 | 828 | if (p == null) { return o; } |
816 | 829 | SQLDataBase sqld = p.Parameters as SQLDataBase; |
830 | + if (FunctionIsNotAvailable(sqld)) { return o; } | |
817 | 831 | |
818 | - getparametersloop:; | |
832 | + getparametersloop:; | |
819 | 833 | |
820 | 834 | List<SQLDataBase.LastUpdatedTrigger> TriggerToExecuteList = new List<SQLDataBase.LastUpdatedTrigger>(); |
821 | 835 | string selectedtrgkey =null; |
... | ... | @@ -1015,7 +1029,7 @@ GO |
1015 | 1029 | bool multirunmode = !string.IsNullOrWhiteSpace(ss.MultirunParameters); |
1016 | 1030 | int commandtimeout = ss.CommandTimeout; |
1017 | 1031 | ReturnInfoJSON result = null; |
1018 | - using (var sqlc = ServerConnectionPool.GetSqlConnection(sqld.SQLCS, open: true)) | |
1032 | + using (var sqlc = ServerConnectionPool.GetSqlConnection(ss.SQLCS, open: true)) | |
1019 | 1033 | { |
1020 | 1034 | if (multirunmode) { result = SQLDataBaseManagerCore.ExecuteMultirunSQLScript(sqlc, ss, ExitAtThisPoint); } |
1021 | 1035 | else |
... | ... | @@ -1085,7 +1099,8 @@ GO |
1085 | 1099 | SQLDataBase sqld = p.Parameters as SQLDataBase; |
1086 | 1100 | try |
1087 | 1101 | { |
1088 | - 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); | |
1102 | + if (FunctionIsNotAvailable(sqld)) { return o; } | |
1103 | + 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); | |
1089 | 1104 | ColorConsole.WriteLine(prefix: " ", text: "[USERID,PASSWORD empty]", bracket: "[]", suffix: $":use windows authentication with current user", f: ConsoleColor.Yellow); |
1090 | 1105 | ColorConsole.WriteLine(prefix: " ", text: "USERID", bracket: "[]", suffix: $":use windows authentication with this user", f: ConsoleColor.Yellow); |
1091 | 1106 | 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 |
1170 | 1185 | SQLDataBase sqld = p.Parameters as SQLDataBase; |
1171 | 1186 | try |
1172 | 1187 | { |
1173 | - ColorConsole.WriteLine(prefix: $"Enter the shrink options. Format:", bracket:"()", text:"OPTION,FreeSpacePercent:", f:ConsoleColor.Yellow); | |
1188 | + if (FunctionIsNotAvailable(sqld)) { return o; } | |
1189 | + ColorConsole.WriteLine(prefix: $"Enter the shrink options. Format:", bracket:"()", text:"OPTION,FreeSpacePercent:", f:ConsoleColor.Yellow); | |
1174 | 1190 | 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); |
1175 | 1191 | 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); |
1176 | 1192 | 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 |
1213 | 1229 | SQLDataBase sqld = p.Parameters as SQLDataBase; |
1214 | 1230 | try |
1215 | 1231 | { |
1216 | - var restoredbname = ColorConsole.ReadLine($"Enter the name of the DB to copy '{sqld.DBName}' to. Empty={sqld.DBName}. EX=exit.", ConsoleColor.Yellow, suffix: " --> "); | |
1232 | + if (FunctionIsNotAvailable(sqld)) { return o; } | |
1233 | + var restoredbname = ColorConsole.ReadLine($"Enter the name of the DB to copy '{sqld.DBName}' to. Empty={sqld.DBName}. EX=exit.", ConsoleColor.Yellow, suffix: " --> "); | |
1217 | 1234 | if (restoredbname.ToUpper() == "EX") { continue; } |
1218 | 1235 | else if (string.IsNullOrWhiteSpace(restoredbname)) { restoredbname = sqld.DBName; } |
1219 | 1236 | ColorConsole.WriteLine("Enter the path for the DB physical files.", ConsoleColor.Yellow); |
... | ... | @@ -1266,7 +1283,7 @@ GO |
1266 | 1283 | ColorConsole.Write($"{st.Xml_Description}", ConsoleColor.Black, ConsoleColor.White); |
1267 | 1284 | var statuscolor = st.Status == SQLDataBase.SQLDBStatus.NoAccess ? ConsoleColor.Red:ConsoleColor.Green; |
1268 | 1285 | ColorConsole.Write(st.Status.ToString(), statuscolor, bracket: "[]", prefix: " ", suffix: ". "); |
1269 | - ColorConsole.Write(st.DBName, statuscolor, bracket: "[]", prefix: "Database ", suffix: ". "); | |
1286 | + if (!string.IsNullOrWhiteSpace(st.DBName)) { ColorConsole.Write(st.DBName, statuscolor, bracket: "[]", prefix: "Database ", suffix: ". "); } | |
1270 | 1287 | ColorConsole.Write(st.DataSource, statuscolor, bracket: "[]", prefix: "from server ", suffix: ". "); |
1271 | 1288 | if (st.Status != SQLDataBase.SQLDBStatus.NoAccess) |
1272 | 1289 | { |
... | ... | @@ -1277,7 +1294,8 @@ GO |
1277 | 1294 | } |
1278 | 1295 | else if (lineix == 1) |
1279 | 1296 | { |
1280 | - ColorConsole.Write($"{st.Xml_BackupFileNameMask}", ConsoleColor.Yellow, prefix: "Backup to:", suffix: ".xxx"); | |
1297 | + if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; | |
1298 | + ColorConsole.Write($"{st.Xml_BackupFileNameMask}", ConsoleColor.Yellow, prefix: "Backup to:", suffix: ".xxx"); | |
1281 | 1299 | ColorConsole.WriteLine(); |
1282 | 1300 | return Menu.MenuItemDisplayerReturnValue.NEXTLINE; |
1283 | 1301 | } |
... | ... | @@ -1289,14 +1307,16 @@ GO |
1289 | 1307 | } |
1290 | 1308 | else if (lineix == 3) |
1291 | 1309 | { |
1292 | - var PhysicalFilesDirectoryPathcolor = st.PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; | |
1310 | + if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; | |
1311 | + var PhysicalFilesDirectoryPathcolor = st.PhysicalFilesDirectoryPath.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; | |
1293 | 1312 | ColorConsole.Write($"{st.PhysicalFilesDirectoryPath}", PhysicalFilesDirectoryPathcolor, prefix: "DB files physical location:", suffix: " "); |
1294 | 1313 | ColorConsole.WriteLine(" "); |
1295 | 1314 | return Menu.MenuItemDisplayerReturnValue.NEXTLINE; |
1296 | 1315 | } |
1297 | 1316 | else if (lineix == 4) |
1298 | 1317 | { |
1299 | - var SizeStringcolor = st.SizeString.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; | |
1318 | + if (string.IsNullOrWhiteSpace(st.DBName)) return Menu.MenuItemDisplayerReturnValue.SAMELINE; | |
1319 | + var SizeStringcolor = st.SizeString.StartsWith("ERR") ? ConsoleColor.Red : ConsoleColor.Yellow; | |
1300 | 1320 | ColorConsole.Write(st.SizeString, SizeStringcolor, prefix: "DB size:", suffix: " "); |
1301 | 1321 | ColorConsole.WriteLine(" "); |
1302 | 1322 | return Menu.MenuItemDisplayerReturnValue.NEXTLINE; |
... | ... | @@ -1307,7 +1327,8 @@ GO |
1307 | 1327 | if (st.Xml_SQLScriptList.Count-1 < lineix-5) { return Menu.MenuItemDisplayerReturnValue.EXIT; } |
1308 | 1328 | var s = st.Xml_SQLScriptList.ToArray()[lineix-5]; |
1309 | 1329 | ColorConsole.Write(s.Key, ConsoleColor.Yellow, bracket: "[]", suffix: " ", prefix: " Script: "); |
1310 | - ColorConsole.WriteLine($"{s.Description} ({s.Name})", ConsoleColor.Yellow); | |
1330 | + ColorConsole.Write(s.Name, ConsoleColor.Yellow, bracket: "[]", suffix: " "); | |
1331 | + ColorConsole.WriteLine(s.Description, ConsoleColor.White); | |
1311 | 1332 | return Menu.MenuItemDisplayerReturnValue.NEXTLINE; |
1312 | 1333 | } |
1313 | 1334 | return Menu.MenuItemDisplayerReturnValue.EXIT; |
... | ... | @@ -1981,18 +2002,18 @@ GO |
1981 | 2002 | /// </param> |
1982 | 2003 | /// <returns></returns> |
1983 | 2004 | |
1984 | - public static ReturnInfoJSON ExecuteMultirunSQLScript(SqlConnection sqlc, SQLDataBase.SQLScript sqlscript, Func<ReturnInfoJSON,TimeSpan?, bool> ExitAtThisPoint=null) | |
2005 | + public static ReturnInfoJSON ExecuteMultirunSQLScript(SqlConnection sqlc,SQLDataBase.SQLScript sqlscript, Func<ReturnInfoJSON,TimeSpan?, bool> ExitAtThisPoint=null) | |
1985 | 2006 | { |
1986 | - ReturnInfoJSON ret1=null; | |
1987 | - string sqltxt = null; | |
1988 | - int? getdbnumofrowsresult=null; | |
1989 | - DateTime? getdbmindateresult=null; | |
2007 | + ReturnInfoJSON ret1 = null; | |
2008 | + string sqltxt = null; | |
2009 | + int? getdbnumofrowsresult = null; | |
2010 | + DateTime? getdbmindateresult = null; | |
1990 | 2011 | |
1991 | 2012 | var multirunresult = new List<KeyValuePair<string, string>>(); |
1992 | 2013 | |
1993 | 2014 | var scriptparameterkvplist = (new Tools.KvpString(sqlscript.ScriptParameters)).ResolveInteractive(); |
1994 | - string sqltxtalmostresolved = scriptparameterkvplist.Substitute(sqlscript.ScriptText); //parameters of the run are still unresolved | |
1995 | - if (sqltxtalmostresolved == null) {return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE));} //won't really get, but we never know... | |
2015 | + string sqltxtalmostresolved = scriptparameterkvplist.Substitute(sqlscript.ScriptText); //parameters of the run are still unresolved | |
2016 | + if (sqltxtalmostresolved == null) { return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE)); } //won't really get, but we never know... | |
1996 | 2017 | |
1997 | 2018 | //get number of total records in the database |
1998 | 2019 | getdbnumofrowsresult = GetDBNumofRows(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); |
... | ... | @@ -2003,27 +2024,27 @@ GO |
2003 | 2024 | getdbmindateresult = GetDBMindate(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); |
2004 | 2025 | if (getdbmindateresult == null) return Finalize(1, multirunresult); |
2005 | 2026 | DateTime mindateTS_before = getdbmindateresult.Value; |
2006 | - var _multirunresult = multirunresult.Select(kvp => new KeyValuePair<string, string>(kvp.Key, kvp.Value)).ToList(); | |
2027 | + var _multirunresult = multirunresult.Select(kvp => new KeyValuePair<string, string>(kvp.Key, kvp.Value)).ToList(); | |
2007 | 2028 | Add(_multirunresult, $"DBRECORDS", $"{numoftotaldbrecords_before}"); |
2008 | 2029 | Add(_multirunresult, $"MINDATE", $"{mindateTS_before}"); |
2009 | 2030 | |
2010 | - var exithere = (ExitAtThisPoint?.Invoke(Finalize(0, _multirunresult),null)) ?? false; | |
2031 | + var exithere = (ExitAtThisPoint?.Invoke(Finalize(0, _multirunresult), null)) ?? false; | |
2011 | 2032 | if (exithere) { Add(_multirunresult, $"Exit requested by user"); return Finalize(0, _multirunresult); } |
2012 | 2033 | |
2013 | 2034 | var multirunparameterskvplist = (new Tools.KvpString(sqlscript.MultirunParameters)).ResolveInteractive(); |
2014 | - if(multirunparameterskvplist == null) { return Finalize(0, Add(multirunresult, ERRMSG_NOMULTIRUNPARAMETERS)); } //user exit with selecting EX | |
2015 | - var smrp = SetMultirunParameters(multirunparameterskvplist, multirunresult); | |
2016 | - if (smrp == null) { return Finalize(1, multirunresult);} | |
2017 | - (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns) = smrp.Value; | |
2035 | + if (multirunparameterskvplist == null) { return Finalize(0, Add(multirunresult, ERRMSG_NOMULTIRUNPARAMETERS)); } //user exit with selecting EX | |
2036 | + var smrp = SetMultirunParameters(multirunparameterskvplist, multirunresult); | |
2037 | + if (smrp == null) { return Finalize(1, multirunresult); } | |
2038 | + (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns) = smrp.Value; | |
2018 | 2039 | |
2019 | 2040 | try |
2020 | 2041 | { |
2021 | - DateTime starttime = DateTime.Now; | |
2042 | + DateTime starttime = DateTime.Now; | |
2022 | 2043 | var limitdatefornextrun = mindateTS_before; |
2023 | 2044 | int exceptioncounter = 0; |
2024 | - const int MAXEXCEPTIONS = 3; //after this number of subsequent exceptions we exit | |
2025 | - int deleteruncounter = 0; | |
2026 | - int runresult; | |
2045 | + const int MAXEXCEPTIONS = 3; //after this number of subsequent exceptions we exit | |
2046 | + int deleteruncounter = 0; | |
2047 | + int runresult; | |
2027 | 2048 | while (true) |
2028 | 2049 | { |
2029 | 2050 | if (limitdatefornextrun >= par_limitdate) break; |
... | ... | @@ -2031,36 +2052,36 @@ GO |
2031 | 2052 | var loople = new List<KeyValuePair<string, string>>(); |
2032 | 2053 | if (limitdatefornextrun > par_limitdate) limitdatefornextrun = par_limitdate; |
2033 | 2054 | Add(loople, $"RUN#{deleteruncounter}"); |
2034 | - try | |
2035 | - { | |
2036 | - sqltxt = Tools.KvpString.Substitute($"{RUNNINGMODE}={RUNNINGMODE_ONERUN};{RUNNINGMODE_ONERUN_PARAMETER_DELETEBEFOREDATE}={limitdatefornextrun:s};", sqltxtalmostresolved); | |
2037 | - if (sqltxt == null) { return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE)); } //won't really get, but we never know... | |
2038 | - ret1 = ExecuteSQLScript(sqlc, sqltxt, sqlscript.CommandTimeout, null); | |
2039 | - Add(loople, $"LIMITDATE", limitdatefornextrun.ToString()); | |
2040 | - Add(loople, $"RETCODE", ret1.ReturnValue.ToString()); | |
2041 | - Add(loople, $"RETMSG", ret1.ReturnMessage); | |
2042 | - | |
2043 | - deleteruncounter++; | |
2044 | - exceptioncounter = 0; | |
2045 | - runresult = 0; | |
2055 | + try | |
2056 | + { | |
2057 | + sqltxt = Tools.KvpString.Substitute($"{RUNNINGMODE}={RUNNINGMODE_ONERUN};{RUNNINGMODE_ONERUN_PARAMETER_DELETEBEFOREDATE}={limitdatefornextrun:s};", sqltxtalmostresolved); | |
2058 | + if (sqltxt == null) { return Finalize(1, Add(multirunresult, ERRMSG_NOTHINGTOEXECUTE)); } //won't really get, but we never know... | |
2059 | + ret1 = ExecuteSQLScript(sqlc, sqltxt, sqlscript.CommandTimeout, null); | |
2060 | + Add(loople, $"LIMITDATE", limitdatefornextrun.ToString()); | |
2061 | + Add(loople, $"RETCODE", ret1.ReturnValue.ToString()); | |
2062 | + Add(loople, $"RETMSG", ret1.ReturnMessage); | |
2063 | + | |
2064 | + deleteruncounter++; | |
2065 | + exceptioncounter = 0; | |
2066 | + runresult = 0; | |
2046 | 2067 | } |
2047 | - catch (Exception ex) | |
2048 | - { | |
2049 | - exceptioncounter++; | |
2050 | - string errmsg = ""; while (ex != null) { errmsg += ex.Message; ex = ex.InnerException; } | |
2051 | - Add(loople, $"EXCEPTION RESULT DeleteRun", errmsg); | |
2068 | + catch (Exception ex) | |
2069 | + { | |
2070 | + exceptioncounter++; | |
2071 | + string errmsg = ""; while (ex != null) { errmsg += ex.Message; ex = ex.InnerException; } | |
2072 | + Add(loople, $"EXCEPTION RESULT DeleteRun", errmsg); | |
2052 | 2073 | runresult = 1; |
2053 | 2074 | if (exceptioncounter > MAXEXCEPTIONS) { return Finalize(1, multirunresult); } |
2054 | 2075 | } |
2055 | - var exitfromloop = (ExitAtThisPoint?.Invoke(Finalize(runresult, loople),new TimeSpan(0,0,5))) ?? false; | |
2076 | + var exitfromloop = (ExitAtThisPoint?.Invoke(Finalize(runresult, loople), new TimeSpan(0, 0, 5))) ?? false; | |
2056 | 2077 | if (exitfromloop) { Add(multirunresult, $"Exit requested by user"); break; } |
2057 | 2078 | Thread.Sleep((int)(par_delaybetweenruns.TotalMilliseconds)); |
2058 | 2079 | } |
2059 | 2080 | |
2060 | 2081 | //get minimum date in the database |
2061 | - getdbmindateresult = GetDBMindate(sqltxtalmostresolved,multirunresult, sqlscript.CommandTimeout,sqlc); | |
2062 | - if (getdbmindateresult==null) return Finalize(1, multirunresult); | |
2063 | - DateTime mindateTS_after = getdbmindateresult.Value; | |
2082 | + getdbmindateresult = GetDBMindate(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); | |
2083 | + if (getdbmindateresult == null) return Finalize(1, multirunresult); | |
2084 | + DateTime mindateTS_after = getdbmindateresult.Value; | |
2064 | 2085 | |
2065 | 2086 | //get number of total records in the database |
2066 | 2087 | getdbnumofrowsresult = GetDBNumofRows(sqltxtalmostresolved, multirunresult, sqlscript.CommandTimeout, sqlc); |
... | ... | @@ -2075,7 +2096,7 @@ GO |
2075 | 2096 | } |
2076 | 2097 | catch (Exception ex) { return Finalize(1, Add(multirunresult, ex)); } |
2077 | 2098 | } |
2078 | - private static (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns)? SetMultirunParameters(Tools.KvpString argkvplist,List<KeyValuePair<string, string>> multirunresult) | |
2099 | + private static (bool par_testmode, DateTime par_limitdate, TimeSpan par_lengthofonerun, TimeSpan par_delaybetweenruns)? SetMultirunParameters(Tools.KvpString argkvplist,List<KeyValuePair<string, string>> multirunresult) | |
2079 | 2100 | { |
2080 | 2101 | bool par_testmode; |
2081 | 2102 | int par_limitdays; |
... | ... | @@ -2628,11 +2649,22 @@ GO |
2628 | 2649 | { |
2629 | 2650 | try |
2630 | 2651 | { |
2631 | - GetPhysicalFilesLocationAndSize(this.SQLCS, out this.SizeString, out this.PhysicalFilesDirectoryPath); | |
2632 | - this.Status = this.PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK; | |
2633 | - this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS); | |
2634 | - this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); | |
2635 | - } | |
2652 | + string dbname = SQLDataBaseManagerCore.GetDBName(this.SQLCS); | |
2653 | + if (string.IsNullOrWhiteSpace(dbname)) | |
2654 | + { | |
2655 | + var sqlc = ServerConnectionPool.GetSqlConnection(this.SQLCS, open: true); | |
2656 | + this.Status = SQLDBStatus.OK; | |
2657 | + this.DBName = ""; | |
2658 | + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); | |
2659 | + } | |
2660 | + else | |
2661 | + { | |
2662 | + GetPhysicalFilesLocationAndSize(this.SQLCS, out this.SizeString, out this.PhysicalFilesDirectoryPath); | |
2663 | + this.Status = this.PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK; | |
2664 | + this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS); | |
2665 | + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS); | |
2666 | + } | |
2667 | + } | |
2636 | 2668 | catch |
2637 | 2669 | { |
2638 | 2670 | this.Status = SQLDBStatus.NoAccess; |
... | ... | @@ -2725,7 +2757,8 @@ GO |
2725 | 2757 | Xml_BackupTimeout = GetValue(nameof(XmlStructure.SQLDataBase.Attributes.BackupTimeout), sqldatabasexml, common.Xml_BackupTimeout); |
2726 | 2758 | |
2727 | 2759 | Xml_SQLDataList = new List<SQLData>(); |
2728 | - var sqldataXmlList = GetAllXElements(sqldatabasexml, nameof(XmlStructure.SQLDataBase.SQLData)); | |
2760 | + IEnumerable<XElement> sqldataXmlList=null; | |
2761 | + try { sqldataXmlList = GetAllXElements(sqldatabasexml, nameof(XmlStructure.SQLDataBase.SQLData)); } catch { } | |
2729 | 2762 | if (sqldataXmlList!=null) { foreach (var sqldataXml in sqldataXmlList) { Xml_SQLDataList.Add(new SQLData(sqldataXml)); } } |
2730 | 2763 | |
2731 | 2764 | Xml_SQLLastUpdatedTriggerList = new List<LastUpdatedTrigger>(); |
... | ... | @@ -2746,7 +2779,7 @@ GO |
2746 | 2779 | Xml_SQLScriptList = new List<SQLScript>(); |
2747 | 2780 | var sqlscriptsXml = GetXElement(sqldatabasexml, nameof(XmlStructure.SQLDataBase.Scripts)); |
2748 | 2781 | var sqlscriptXmlList = GetAllXElements(sqlscriptsXml, nameof(XmlStructure.SQLDataBase.Scripts.Script)); |
2749 | - if (sqlscriptXmlList != null) { int scriptindex = 1; foreach (var sqlscriptXml in sqlscriptXmlList) { Xml_SQLScriptList.Add(new SQLScript(sqlscriptXml, Xml_ScriptCommandTimeout,scriptindex++)); } } | |
2782 | + if (sqlscriptXmlList != null) { int scriptindex = 1; foreach (var sqlscriptXml in sqlscriptXmlList) { Xml_SQLScriptList.Add(new SQLScript(sqlscriptXml, Xml_SQLConnectionString,Xml_ScriptCommandTimeout, scriptindex++)); } } | |
2750 | 2783 | } |
2751 | 2784 | #endregion xml constructor |
2752 | 2785 | #region cloner constructor |
... | ... | @@ -2857,8 +2890,9 @@ GO |
2857 | 2890 | public static class ScriptCommandTimeout { public static class Values { public const int DEFAULT = 10000; } } |
2858 | 2891 | public static class Parameters { public static class Values { public const string DEFAULT = ""; } } |
2859 | 2892 | public static class Multirun { public static class Values { public const string DEFAULT = ""; } } |
2860 | - } | |
2861 | - } | |
2893 | + public static class SQLConnectionString { public static class Values { public const string DEFAULT = null; } } | |
2894 | + } | |
2895 | + } | |
2862 | 2896 | } |
2863 | 2897 | } |
2864 | 2898 | } |
... | ... | @@ -2874,10 +2908,15 @@ GO |
2874 | 2908 | public int CommandTimeout = 10000; |
2875 | 2909 | public string ScriptParameters=null; |
2876 | 2910 | public string MultirunParameters=null; |
2911 | + public string SQLConnectionString=null; | |
2912 | + public string SQLCS | |
2913 | + { | |
2914 | + get { return XmlProcessing.ConnectionStringStore.GetSQL(this.SQLConnectionString); } | |
2915 | + } | |
2877 | 2916 | |
2878 | - public SQLScript() { } | |
2917 | + public SQLScript() { } | |
2879 | 2918 | public SQLScript(SQLScript sqls) { Name = sqls.Name; Description = sqls.Description; ScriptText= sqls.ScriptText; } |
2880 | - public SQLScript(XElement sqlscriptXml, int defaultcommandtimeout, int index) | |
2919 | + public SQLScript(XElement sqlscriptXml,string sqlconnectionstring, int defaultcommandtimeout, int index) | |
2881 | 2920 | { |
2882 | 2921 | ScriptParameters = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Parameters.Values.DEFAULT); |
2883 | 2922 | MultirunParameters= GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Multirun), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Multirun.Values.DEFAULT); |
... | ... | @@ -2886,6 +2925,8 @@ GO |
2886 | 2925 | Name = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Name), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Name.Values.DEFAULT); |
2887 | 2926 | FilePath = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.File), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.File.Values.DEFAULT); |
2888 | 2927 | Description= GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.Description), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.Description.Values.DEFAULT); |
2928 | + SQLConnectionString = GetValue(nameof(XmlStructure.SQLDataBase.Scripts.Script.Attributes.SQLConnectionString), sqlscriptXml, XmlStructure.SQLDataBase.Scripts.Script.Attributes.SQLConnectionString.Values.DEFAULT); | |
2929 | + if (SQLConnectionString == null) SQLConnectionString = sqlconnectionstring; | |
2889 | 2930 | |
2890 | 2931 | Tools.KvpString.Resolve(ScriptParameters, this.Name, out this.Name, disableinteractive: true); |
2891 | 2932 | Tools.KvpString.Resolve(ScriptParameters, this.Description, out this.Description, disableinteractive: true); |
... | ... | @@ -3033,16 +3074,16 @@ GO |
3033 | 3074 | } |
3034 | 3075 | public static void Open(SqlConnection sqlc) |
3035 | 3076 | { |
3036 | - if (IsMasterInacessible(sqlc) || IsInacessible(sqlc)) | |
3037 | - { | |
3038 | - throw new Exception($"DB {sqlc.Database} on server {sqlc.DataSource} is inaccessible!"); | |
3039 | - } | |
3040 | - try { sqlc.Open(); } | |
3041 | - catch (Exception ex) | |
3077 | + if (IsMasterInacessible(sqlc) || IsInacessible(sqlc)) { throw new Exception($"SQL server {sqlc.DataSource} is inaccessible!"); } | |
3078 | + if (!string.IsNullOrWhiteSpace(sqlc.Database)) | |
3042 | 3079 | { |
3043 | - MarkMasterInacessible(sqlc); | |
3044 | - MarkInacessible(sqlc); | |
3045 | - throw ex; | |
3080 | + try { sqlc.Open(); } | |
3081 | + catch (Exception ex) | |
3082 | + { | |
3083 | + MarkMasterInacessible(sqlc); | |
3084 | + MarkInacessible(sqlc); | |
3085 | + throw ex; | |
3086 | + } | |
3046 | 3087 | } |
3047 | 3088 | } |
3048 | 3089 | private static bool IsMasterDBConnected(SqlConnection sqlc) | ... | ... |
Vrh.Log4Pro.MaintenanceConsole/Properties/AssemblyInfo.cs
... | ... | @@ -32,5 +32,5 @@ using System.Runtime.InteropServices; |
32 | 32 | // You can specify all the values or you can default the Build and Revision Numbers |
33 | 33 | // by using the '*' as shown below: |
34 | 34 | // [assembly: AssemblyVersion("1.0.*")] |
35 | -[assembly: AssemblyVersion("1.31.2.0")] | |
36 | -[assembly: AssemblyFileVersion("1.31.2.0")] | |
35 | +[assembly: AssemblyVersion("1.31.3.0")] | |
36 | +[assembly: AssemblyFileVersion("1.31.3.0")] | ... | ... |