{
{
{
ToggleConnectionStringProtection
(System.Windows.Forms.Application.ExecutablePath,
true); }
{
ToggleConnectionStringProtection
(System.Windows.Forms.Application.ExecutablePath,
false); }
{
// Define the Dpapi provider name.
string strProvider
= "DataProtectionConfigurationProvider"; // string strProvider = "RSAProtectedConfigurationProvider";
System.Configuration.Configuration oConfiguration
= null; System.Configuration.ConnectionStringsSection oSection
= null;
{
// Open the configuration file and retrieve
// the connectionStrings section.
// For Web!
// oConfiguration = System.Web.Configuration.
// WebConfigurationManager.OpenWebConfiguration("~");
// For Windows!
// Takes the executable file name without the config extension.
oConfiguration = System.Configuration.ConfigurationManager.
OpenExeConfiguration(pathName);
{
oSection
= oConfiguration
.GetSection("connectionStrings") as System.Configuration.ConnectionStringsSection;
{
if ((!(oSection
.ElementInformation.IsLocked)) && (!(oSection.SectionInformation.IsLocked)))
{
{
if (!(oSection
.SectionInformation.IsProtected)) {
// Encrypt the section.
oSection.SectionInformation.ProtectSection
(strProvider);
}
}
{
if (oSection
.SectionInformation.IsProtected) {
// Remove encryption.
oSection.SectionInformation.UnprotectSection();
}
}
}
{
// Indicates whether the associated configuration section
// will be saved even if it has not been modified.
oSection
.SectionInformation.ForceSave = true;
// Save the current configuration.
oConfiguration.Save();
}
}
}
}
catch (System.Exception ex
) {
}
{
}
}
}
}