I'm trying to encrypt a connection string in an app.config.
This is the app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="test" connectionString="user
id=testuser;password=testpwd;data source=testdb;persist security
info=False;"/>
</connectionStrings>
</configuration>
Here's the code:
private void btnEncrypt_Click(object sender, EventArgs e)
{
Configuration config =
ConfigurationManager.OpenExeConfiguration(Configur ationUserLevel.None);
ConnectionStringsSection section =
(ConnectionStringsSection)
config.GetSection("connectionStrings");
if (!section.SectionInformation.IsProtected)
section.SectionInformation.ProtectSection("DataPro tectionConfigurationProvider");
config.Save(ConfigurationSaveMode.Full);
txtDisplay.Text = "Encrypted";
}
I have
using System.Configuration;
at the top and a reference to System.Configuration in the references.
When I run it, it displays the "encrypted" message. There are no errors and
it completes, yet the app,.config section is not encrypted.
Any help is appreciated.
Thanks,
Mike