diff --git a/PROMS/VEPROMS User Interface/frmRODbProperties.cs b/PROMS/VEPROMS User Interface/frmRODbProperties.cs index aeae059e..81b27130 100644 --- a/PROMS/VEPROMS User Interface/frmRODbProperties.cs +++ b/PROMS/VEPROMS User Interface/frmRODbProperties.cs @@ -9,6 +9,7 @@ using System.Windows.Forms; using System.IO; using VEPROMS.CSLA.Library; using DevComponents.DotNetBar; +using Volian.Base.Library; namespace VEPROMS { @@ -70,9 +71,25 @@ namespace VEPROMS _origFolderPath = (_roDbInfo == null) ? null : _roDbInfo.FolderPath; _origSQLConnect = (_roDbInfo == null) ? null : (_roDbInfo.DBConnectionString == null || _roDbInfo.DBConnectionString == "" || _roDbInfo.DBConnectionString == "cstring") ? null : _roDbInfo.DBConnectionString; // Disable the OK button when initialized. Enable it if the user makes changes + ppBtnTestSQL.Visible = ppBtnTestSQL.Enabled = CanMigrateRoAccessToSql(roDbInfo); + ppTxtSQL.Visible = ppTxtSQL.Enabled = CanMigrateRoAccessToSql(roDbInfo); + ppLblSQL.Visible = CanMigrateRoAccessToSql(roDbInfo); ppBtnOk.Enabled = false; } + private bool CanMigrateRoAccessToSql(RODbInfo rODbi) + { + // C2017-003: This method is used to determine whether the sql server version can be used & if there is data. + // A command line argument 'RoInSql'. For now, this argument must be used to allow code to run for ro->sql. Later + // this will be changed so that if argument is used, the program does NOT include test button & text box to allow + // entry of sql server connection string + if (!Volian.Base.Library.VlnSettings.GetCommandFlag("RoInSql")) return false; + // The following conditions must be true in order to migrate the set the connection string. + // 1) the user must be an admin + UserInfo ui = UserInfo.GetByUserID(VlnSettings.UserID); + if (!ui.IsAdministrator()) return false; + return true; + } private void ppBtnFldrDlg_Click(object sender, EventArgs e) { FolderBrowserDialog dlgROFolder = new FolderBrowserDialog(); @@ -108,7 +125,25 @@ namespace VEPROMS { // C2017-003: ro in sql. 'cstring' in connection string represents using MS Access database // if connect string is null, set connect string to "cstring" otherwise, use what user typed in: - roDb.DBConnectionString = (ppTxtSQL.Text == null || ppTxtSQL.Text == "") ? "cstring" : ppTxtSQL.Text; + // first check if connection can be made to what was entered: + bool canconnect = false; + try + { + using (SqlConnection connection = new SqlConnection(ppTxtSQL.Text)) + { + try + { + connection.Open(); + canconnect = (connection.State == ConnectionState.Open); + } + catch (SqlException) { } + } + } + catch (Exception ex) {} + if (canconnect) + roDb.DBConnectionString = (ppTxtSQL.Text == null || ppTxtSQL.Text == "") ? "cstring" : ppTxtSQL.Text; + else + MessageBox.Show("SQL Connection failed, connection string won't be saved.", "Cannot save connection data"); } if (_origFolderPath != ppTxtPath.Text) {