Click here to Skip to main content
15,887,427 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hello!

I am trying to save MappedExe configuration file within user's AppData directory.
Problem occurs when I try to save encrypted connectionString.

This is the exception's message :
"System.Configuration.ConfigurationErrorsException: An error occured executing section handler for connectionStrings.-->System.Configuration.ConfigurationErrorsException: Failed to encrypt the section 'connectionStrings' using provider 'RsaProtectedConfigurationProvider'. Error message from provider: Object already exists.


It only occurs with common users within domain, I have no problems with admins, power users, work-groups etc.

This is part of code responsible for saving configuration data:

C#
if (_configuration.ConnectionStrings.ConnectionStrings[Application.ProductName] == null)
{
    _configuration.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings(Application.ProductName, 
                                                                                        _connStringBuilder.ToString()));
}
else
{
    _configuration.ConnectionStrings.ConnectionStrings[Application.ProductName].ConnectionString = _connStringBuilder.ToString();
}
try
{
    if (!_configuration.ConnectionStrings.SectionInformation.IsProtected)
    {
        _configuration.ConnectionStrings.SectionInformation.ForceSave = true;
        _configuration.ConnectionStrings.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
    }

    _configuration.Save(ConfigurationSaveMode.Minimal);
}
catch (Exception ex)
{
#if DEBUG
    MessageBox.Show(ex.ToString() + "\n" + ex.StackTrace);
#else
    throw;
#endif
}



Can you help me?

P.S. This is a ClickOnce solution.
Posted
Updated 28-Jul-16 7:37am
v5

The actual encryption is either based on an RSA key or DPAPI, which means the key is stored in the local machine. The decryption can only be done on the machine where the app config was encrypted (unless you export the RSA key and import it into another machine).
 
Share this answer
 
Comments
Oshtri Deka 13-Sep-11 10:08am    
It's RSA and everything is done locally.
Source of entire problem is fact that domain user's rights are to restricted for this kind of protection ("peeking" inside windir), so I had to tinker around the problem.
I've made custom methods for encryption and decryption and it works fine.

My apologies for delayed answer.
 
Share this answer
 
You need to run command as administrator ;)
 
Share this answer
 
Comments
Richard Deeming 28-Jul-16 14:48pm    
This question was asked, answered, and solved almost FIVE YEARS AGO.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900