Commit 08a28ecbf94b1d1b5a3edca41091cf21aca0f411

Authored by Schwirg László
1 parent 1ff12b69

v1.31.4.0

-Script/SQLConnectionString= és SQLDataBase/SQLConnectionString= attributumokba vesszővel határolva lehet beírni a connstr neveket, amik közül választani lehet
Vrh.Log4Pro.MaintenanceConsole/Manager - SQLDataBaseManager.cs
... ... @@ -112,7 +112,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS
112 112 SQLDataBase sqld = p.Parameters as SQLDataBase;
113 113 try
114 114 {
115   - if (FunctionIsNotAvailable(sqld)) { return o; }
  115 + if (NoDBNameSpecified(sqld)) { return o; }
116 116 SQLDataBaseManagerCore.BackupSqlData(sqld,TS);
117 117 ColorConsole.WriteLine($"SQLDB data scripts created. Name:{sqld.Xml_Description}", ConsoleColor.Green);
118 118 }
... ... @@ -142,7 +142,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS
142 142 SQLDataBase sqld = p.Parameters as SQLDataBase;
143 143 try
144 144 {
145   - if (FunctionIsNotAvailable(sqld)) { return o; }
  145 + if (NoDBNameSpecified(sqld)) { return o; }
146 146 SQLDataBaseManagerCore.BackupSqlScripts(sqld,TS);
147 147 ColorConsole.WriteLine($"SQLDB code scripts created. Name:{sqld.Xml_Description}", ConsoleColor.Green);
148 148 }
... ... @@ -172,7 +172,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS
172 172 SQLDataBase sqld = p.Parameters as SQLDataBase;
173 173 try
174 174 {
175   - if (FunctionIsNotAvailable(sqld)) { return o; }
  175 + if (NoDBNameSpecified(sqld)) { return o; }
176 176 SQLDataBaseManagerCore.CreateBackup(sqld,null,TS);
177 177 ColorConsole.WriteLine($"Database backup created. Name:{sqld.DBName}", ConsoleColor.Green);
178 178 }
... ... @@ -180,10 +180,10 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS
180 180 }
181 181 return o;
182 182 }
183   - private static bool FunctionIsNotAvailable(SQLDataBase ssqldb)
  183 + private static bool NoDBNameSpecified(SQLDataBase ssqldb)
184 184 {
185 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; }
  186 + if (string.IsNullOrWhiteSpace(SQLDataBaseManagerCore.GetDBName(ssqldb.SQLCS))) { ColorConsole.WriteLine(FUNNOTAVAILTXT, ConsoleColor.Red); ssqldb.DBName = "master"; return true; }
187 187 return false;
188 188 }
189 189 private static object RestoreDataBase(object parameter, object o)
... ... @@ -208,7 +208,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS
208 208 SQLDataBase sqld = p.Parameters as SQLDataBase;
209 209 try
210 210 {
211   - if (FunctionIsNotAvailable(sqld)) { return o; }
  211 + if (NoDBNameSpecified(sqld)) { return o; }
212 212 var targetdirectorypath = sqld.Xml_PhysicalFilesDirectoryPath;
213 213 var targetdbname = sqld.DBName;
214 214 bool restorefromzip = sqld.Xml_CreateZip;
... ... @@ -505,7 +505,7 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS
505 505  
506 506 var p = sr.SelectedParameterList.FirstOrDefault();
507 507 SQLDataBase sqld = p.Parameters as SQLDataBase;
508   - if (FunctionIsNotAvailable(sqld)) { return o; }
  508 + if (NoDBNameSpecified(sqld)) { return o; }
509 509  
510 510 getparametersloop:
511 511 List<SQLDataBase.DBUser> DbusrToExecuteList = new List<SQLDataBase.DBUser>();
... ... @@ -656,8 +656,8 @@ namespace Vrh.Log4Pro.MaintenanceConsole.SQLDataBaseManagerNS
656 656 var DateTimeNow = DateTime.Now;
657 657  
658 658 movedbanswer = YesOrNo_MoveDbToRemoteServer(config, selectedsqldbindexes);
659   - if (FunctionIsNotAvailable(movedbanswer.Dbfrom)) { continue; }
660   - if (FunctionIsNotAvailable(movedbanswer.Dbto)) { continue; }
  659 + if (NoDBNameSpecified(movedbanswer.Dbfrom)) { continue; }
  660 + if (NoDBNameSpecified(movedbanswer.Dbto)) { continue; }
661 661 if (movedbanswer.Exit) break;
662 662 if (movedbanswer.Yes)
663 663 {
... ... @@ -827,7 +827,7 @@ GO
827 827 var p = sr.SelectedParameterList.FirstOrDefault();
828 828 if (p == null) { return o; }
829 829 SQLDataBase sqld = p.Parameters as SQLDataBase;
830   - if (FunctionIsNotAvailable(sqld)) { return o; }
  830 + if (NoDBNameSpecified(sqld)) { return o; }
831 831  
832 832 getparametersloop:;
833 833  
... ... @@ -1031,6 +1031,7 @@ GO
1031 1031 ReturnInfoJSON result = null;
1032 1032 using (var sqlc = ServerConnectionPool.GetSqlConnection(ss.SQLCS, open: true))
1033 1033 {
  1034 + if (string.IsNullOrWhiteSpace(sqlc.Database)) { sqlc.ChangeDatabase("master"); }
1034 1035 if (multirunmode) { result = SQLDataBaseManagerCore.ExecuteMultirunSQLScript(sqlc, ss, ExitAtThisPoint); }
1035 1036 else
1036 1037 {
... ... @@ -1099,7 +1100,7 @@ GO
1099 1100 SQLDataBase sqld = p.Parameters as SQLDataBase;
1100 1101 try
1101 1102 {
1102   - if (FunctionIsNotAvailable(sqld)) { return o; }
  1103 + if (NoDBNameSpecified(sqld)) { return o; }
1103 1104 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);
1104 1105 ColorConsole.WriteLine(prefix: " ", text: "[USERID,PASSWORD empty]", bracket: "[]", suffix: $":use windows authentication with current user", f: ConsoleColor.Yellow);
1105 1106 ColorConsole.WriteLine(prefix: " ", text: "USERID", bracket: "[]", suffix: $":use windows authentication with this user", f: ConsoleColor.Yellow);
... ... @@ -1185,7 +1186,7 @@ GO
1185 1186 SQLDataBase sqld = p.Parameters as SQLDataBase;
1186 1187 try
1187 1188 {
1188   - if (FunctionIsNotAvailable(sqld)) { return o; }
  1189 + if (NoDBNameSpecified(sqld)) { return o; }
1189 1190 ColorConsole.WriteLine(prefix: $"Enter the shrink options. Format:", bracket:"()", text:"OPTION,FreeSpacePercent:", f:ConsoleColor.Yellow);
1190 1191 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);
1191 1192 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);
... ... @@ -1229,7 +1230,7 @@ GO
1229 1230 SQLDataBase sqld = p.Parameters as SQLDataBase;
1230 1231 try
1231 1232 {
1232   - if (FunctionIsNotAvailable(sqld)) { return o; }
  1233 + if (NoDBNameSpecified(sqld)) { return o; }
1233 1234 var restoredbname = ColorConsole.ReadLine($"Enter the name of the DB to copy '{sqld.DBName}' to. Empty={sqld.DBName}. EX=exit.", ConsoleColor.Yellow, suffix: " --> ");
1234 1235 if (restoredbname.ToUpper() == "EX") { continue; }
1235 1236 else if (string.IsNullOrWhiteSpace(restoredbname)) { restoredbname = sqld.DBName; }
... ... @@ -1301,6 +1302,7 @@ GO
1301 1302 }
1302 1303 else if (lineix == 2)
1303 1304 {
  1305 + if (!st.isSQLCSselected) { return Menu.MenuItemDisplayerReturnValue.SAMELINE; }
1304 1306 ColorConsole.Write($"{st.SQLCS}", ConsoleColor.Yellow, prefix: "SQL DB connection:", suffix: ", ");
1305 1307 ColorConsole.WriteLine(" ");
1306 1308 return Menu.MenuItemDisplayerReturnValue.NEXTLINE;
... ... @@ -2637,10 +2639,42 @@ GO
2637 2639 public SQLDBStatus Status;
2638 2640 public string PhysicalFilesDirectoryPath;
2639 2641 public string SizeString;
  2642 + public bool isSQLCSselected
  2643 + {
  2644 + get
  2645 + {
  2646 + var sqlcsList = this.Xml_SQLConnectionString.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  2647 + return sqlcsList.Count() == 1 || !string.IsNullOrWhiteSpace(this.Xml_SQLConnectionStringSelected);
  2648 + }
  2649 + }
2640 2650 public string SQLCS
2641 2651 {
2642   - get { return XmlProcessing.ConnectionStringStore.GetSQL(this.Xml_SQLConnectionString); }
  2652 + get
  2653 + {
  2654 + if (string.IsNullOrWhiteSpace(this.Xml_SQLConnectionStringSelected)) { SelectSQLConnectionString(); }
  2655 + if (string.IsNullOrWhiteSpace(this.Xml_SQLConnectionStringSelected)) { return null; }
  2656 + return XmlProcessing.ConnectionStringStore.GetSQL(this.Xml_SQLConnectionStringSelected);
  2657 + }
2643 2658 }
  2659 + private string Xml_SQLConnectionStringSelected;
  2660 +
  2661 + public void SelectSQLConnectionString(int? forceselection=null)
  2662 + {
  2663 + this.Xml_SQLConnectionStringSelected = null;
  2664 + var sqlcsList = this.Xml_SQLConnectionString.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  2665 + if (forceselection.HasValue)
  2666 + {
  2667 + if (forceselection.Value >=0 && sqlcsList.Count() > forceselection.Value) { this.Xml_SQLConnectionStringSelected = sqlcsList[forceselection.Value]; }
  2668 + return;
  2669 + }
  2670 + else
  2671 + {
  2672 + if (sqlcsList.Count() == 1) { this.Xml_SQLConnectionStringSelected = sqlcsList[0]; return; }
  2673 + var selection = ColorConsole.ReadLine("Select SQL connection string to use:", bracket: "[]", suffix: "ENTER==first", validitylist: sqlcsList);
  2674 + if (selection == "EX") return;
  2675 + if (string.IsNullOrWhiteSpace(selection)) { this.Xml_SQLConnectionStringSelected = sqlcsList[0]; } else { this.Xml_SQLConnectionStringSelected = selection; }
  2676 + }
  2677 + }
2644 2678 #endregion fields
2645 2679 public enum SQLDBStatus { NoAccess, OK, }
2646 2680  
... ... @@ -2649,29 +2683,44 @@ GO
2649 2683 {
2650 2684 try
2651 2685 {
2652   - string dbname = SQLDataBaseManagerCore.GetDBName(this.SQLCS);
2653   - if (string.IsNullOrWhiteSpace(dbname))
  2686 + if (!this.isSQLCSselected)
2654 2687 {
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
  2688 + this.Status = SQLDBStatus.OK;
  2689 + this.DBName = "";
  2690 + this.DataSource = this.Xml_SQLConnectionString;
  2691 + }
  2692 + else
2661 2693 {
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   - }
  2694 + string dbname = SQLDataBaseManagerCore.GetDBName(this.SQLCS);
  2695 + if (string.IsNullOrWhiteSpace(dbname))
  2696 + {
  2697 + var sqlc = ServerConnectionPool.GetSqlConnection(this.SQLCS, open: true);
  2698 + this.Status = SQLDBStatus.OK;
  2699 + this.DBName = "";
  2700 + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS);
  2701 + }
  2702 + else
  2703 + {
  2704 + GetPhysicalFilesLocationAndSize(this.SQLCS, out this.SizeString, out this.PhysicalFilesDirectoryPath);
  2705 + this.Status = this.PhysicalFilesDirectoryPath.StartsWith("ERR") ? SQLDBStatus.NoAccess : SQLDBStatus.OK;
  2706 + this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS);
  2707 + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS);
  2708 + }
  2709 + }
2667 2710 }
2668 2711 catch
2669 2712 {
2670 2713 this.Status = SQLDBStatus.NoAccess;
2671 2714 this.PhysicalFilesDirectoryPath = "";
2672   - this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS);
2673   - this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS);
2674   - this.SizeString = "";
  2715 + this.DBName = "";
  2716 + this.DataSource = "";
  2717 + this.SizeString = "";
  2718 + try
  2719 + {
  2720 + this.DBName = SQLDataBaseManagerCore.GetDBName(this.SQLCS);
  2721 + this.DataSource = SQLDataBaseManagerCore.GetDataSource(this.SQLCS);
  2722 + }
  2723 + catch { }
2675 2724 }
2676 2725 return this;
2677 2726 }
... ... @@ -2909,9 +2958,41 @@ GO
2909 2958 public string ScriptParameters=null;
2910 2959 public string MultirunParameters=null;
2911 2960 public string SQLConnectionString=null;
  2961 + private string SQLConnectionStringSelected=null;
  2962 + public bool isSQLCSselected
  2963 + {
  2964 + get
  2965 + {
  2966 + var sqlcsList = this.SQLConnectionString.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  2967 + return sqlcsList.Count() == 1 || !string.IsNullOrWhiteSpace(this.SQLConnectionStringSelected);
  2968 + }
  2969 + }
2912 2970 public string SQLCS
2913 2971 {
2914   - get { return XmlProcessing.ConnectionStringStore.GetSQL(this.SQLConnectionString); }
  2972 + get
  2973 + {
  2974 + if (string.IsNullOrWhiteSpace(this.SQLConnectionStringSelected)) { SelectSQLConnectionString(); }
  2975 + if (string.IsNullOrWhiteSpace(this.SQLConnectionStringSelected)) { return null; }
  2976 + return XmlProcessing.ConnectionStringStore.GetSQL(this.SQLConnectionStringSelected);
  2977 + }
  2978 + }
  2979 +
  2980 + public void SelectSQLConnectionString(int? forceselection = null)
  2981 + {
  2982 + this.SQLConnectionStringSelected = null;
  2983 + var sqlcsList = this.SQLConnectionString.Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries).ToList();
  2984 + if (forceselection.HasValue)
  2985 + {
  2986 + if (forceselection.Value >= 0 && sqlcsList.Count() > forceselection.Value) { this.SQLConnectionStringSelected = sqlcsList[forceselection.Value]; }
  2987 + return;
  2988 + }
  2989 + else
  2990 + {
  2991 + if (sqlcsList.Count() == 1) { this.SQLConnectionStringSelected = sqlcsList[0]; return; }
  2992 + var selection = ColorConsole.ReadLine("Select SQL connection string to use:", bracket: "[]", suffix: "[ENTER]==first", validitylist: sqlcsList);
  2993 + if (selection == "EX") return;
  2994 + if (string.IsNullOrWhiteSpace(selection)) { this.SQLConnectionStringSelected = sqlcsList[0]; } else { this.SQLConnectionStringSelected = selection; }
  2995 + }
2915 2996 }
2916 2997  
2917 2998 public SQLScript() { }
... ... @@ -3066,7 +3147,8 @@ GO
3066 3147 {
3067 3148 var scb = new SqlConnectionStringBuilder(sqlconnectionstring);
3068 3149 if (!string.IsNullOrWhiteSpace(dbname)) { scb.InitialCatalog = dbname; }
3069   - if (!string.IsNullOrWhiteSpace(userid) && !string.IsNullOrWhiteSpace(userpassword)) { scb.UserID = userid; scb.Password = userpassword; }
  3150 + if (string.IsNullOrWhiteSpace(scb.InitialCatalog)) { scb.InitialCatalog = "master"; scb.AttachDBFilename = ""; }
  3151 + if (!string.IsNullOrWhiteSpace(userid) && !string.IsNullOrWhiteSpace(userpassword)) { scb.UserID = userid; scb.Password = userpassword; }
3070 3152 else if (!string.IsNullOrWhiteSpace(userid) && string.IsNullOrWhiteSpace(userpassword)) { scb.UserID = userid; scb.IntegratedSecurity = true; }
3071 3153 var sqlc = new SqlConnection(scb.ToString());
3072 3154 if (open) Open(sqlc);
... ... @@ -3075,15 +3157,12 @@ GO
3075 3157 public static void Open(SqlConnection sqlc)
3076 3158 {
3077 3159 if (IsMasterInacessible(sqlc) || IsInacessible(sqlc)) { throw new Exception($"SQL server {sqlc.DataSource} is inaccessible!"); }
3078   - if (!string.IsNullOrWhiteSpace(sqlc.Database))
  3160 + try { sqlc.Open(); }
  3161 + catch (Exception ex)
3079 3162 {
3080   - try { sqlc.Open(); }
3081   - catch (Exception ex)
3082   - {
3083   - MarkMasterInacessible(sqlc);
3084   - MarkInacessible(sqlc);
3085   - throw ex;
3086   - }
  3163 + MarkMasterInacessible(sqlc);
  3164 + MarkInacessible(sqlc);
  3165 + throw ex;
3087 3166 }
3088 3167 }
3089 3168 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.3.0")]
36   -[assembly: AssemblyFileVersion("1.31.3.0")]
  35 +[assembly: AssemblyVersion("1.31.4.0")]
  36 +[assembly: AssemblyFileVersion("1.31.4.0")]
... ...