public static void SetConnString(string ConnectionString) { var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); var appSettings = configFile.AppSettings.Settings; //appSettings["ConnectionString"].Value = ClsUtility.Encrypt(ConnectionString); XmlDocument XmlDoc = new XmlDocument(); //Loading the Config file XmlDoc.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); foreach (XmlElement xElement in XmlDoc.DocumentElement) { if (xElement.Name == "appSettings") { //setting the coonection string xElement.FirstChild.Attributes[1].Value = ClsUtility.Encrypt(ConnectionString); } } //writing the connection string in config file XmlDoc.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); // configFile.AppSettings.SectionInformation.ForceSave = true; //configFile.Save(ConfigurationSaveMode.Modified); //ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); //Application.UserAppDataRegistry.SetValue("ConnectionString", ClsUtility.Encrypt(ConnectionString)); }
public static String GetConnString() { //var configFile = ConfigurationManager.OpenExeConfiguration(@"App.Config"); //var appSettings = configFile.AppSettings.Settings; //return ClsUtility.Decrypt(appSettings["ConnectionString"].Value); string scon = ConfigurationManager.AppSettings["ConnectionString"]; return(ClsUtility.Decrypt(scon)); /*string versionDependent = Application.UserAppDataRegistry.Name; * string versionIndependent = versionDependent.Substring(0, versionDependent.LastIndexOf("\\")); * * * string ConnectionString = String.Empty; * //if (Application.UserAppDataRegistry.GetValue("ConnectionString") != null) * //return ClsUtility.Decrypt(Application.UserAppDataRegistry.GetValue("ConnectionString").ToString()); * if (Registry.GetValue(versionIndependent, "ConnectionString", null) != null) * return ClsUtility.Decrypt(Registry.GetValue(versionIndependent, "ConnectionString", null).ToString()); * else return ConnectionString;*/ }