private void UpdateConnectionStringValue(string strConnectionString, ConnectionType typeCon) { try { Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); if (typeCon.Equals(ConnectionType.Online)) { config.AppSettings.Settings["DynamicsConnectionStringOnline"].Value = strConnectionString; } if (typeCon.Equals(ConnectionType.OnPremise)) { config.AppSettings.Settings["DynamicsConnectionStringOnPremise"].Value = strConnectionString; } config.Save(ConfigurationSaveMode.Modified); ConfigurationManager.RefreshSection(config.AppSettings.SectionInformation.Name); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void FillLoginDetails(ConnectionType typeCon) { try { string strConnectionString; if (typeCon.Equals(ConnectionType.Online)) { strConnectionString = ConfigurationManager.AppSettings["DynamicsConnectionStringOnline"]; if (string.IsNullOrEmpty(strConnectionString)) { return; } string[] strParams = strConnectionString.Split(';'); foreach (string strParam in strParams) { string strKey = strParam.Split('=')[0]; string strValue = strParam.Split('=')[1]; if (strKey.Equals("Url")) { if (strValue.LastIndexOf('/') != 0) { txtServerOnline.Text = strValue.Substring(0, strValue.LastIndexOf('/')); } else { txtServerOnline.Text = strValue; } } else { if (strKey.Equals("Username")) { txtUserNameOnline.Text = strValue; } else { if (strKey.Equals("Password")) { txtPasswordOnline.Password = strValue; } } } } } if (typeCon.Equals(ConnectionType.OnPremise)) { strConnectionString = ConfigurationManager.AppSettings["DynamicsConnectionStringOnPremise"]; if (string.IsNullOrEmpty(strConnectionString)) { return; } string[] strParams = strConnectionString.Split(';'); foreach (string strParam in strParams) { string strKey = strParam.Split('=')[0]; string strValue = strParam.Split('=')[1]; strValue = strValue.Substring(strValue.IndexOf('{') + 1, strValue.LastIndexOf('}') - 1); if (strKey.Equals("Url")) { if (strValue.LastIndexOf('/') != 0) { txtServerOnPremise.Text = strValue.Substring(0, strValue.LastIndexOf('/')); } else { txtServerOnPremise.Text = strValue; } } else { if (strKey.Equals("Username")) { txtUserNameOnPremise.Text = strValue; } else { if (strKey.Equals("Password")) { txtPasswordOnPremise.Password = strValue; } else { if (strKey.Equals("Domain")) { txtDomainOnPremise.Text = strValue; } } } } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }