Create app.config in wpf (C #)
<?xml version="1.0"?> <configuration> <connectionStrings> <clear /> <add name="Name" providerName="MySql.Data" connectionString="Server=.net;Uid=;Pwd=H;Database=;charset=utf8;Allow Zero Datetime=true;" /> </connectionStrings> </configuration>
C # code used:
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); ConnectionStringsSection conStr = config.ConnectionStrings; if (!conStr.SectionInformation.IsProtected) { conStr.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider"); conStr.SectionInformation.ForceSave = true; config.Save(); } else { foreach (ConnectionStringSettings ss in conStr.ConnectionStrings) Console.WriteLine(ss); Console.Read(); }
config.Save(); - raises an exception:
{"Failed to encrypt the" connectionStrings "section with the provider 'RsaProtectedConfigurationProvider. Error message from provider: object already exists. \ R \ n"}
security c # wpf connection-string
Mediator
source share