Problem with Hands On Lab for DAAB

Topics: Data Access Application Block
Mar 22, 2007 at 10:21 AM
Hi I was trying Hands On Lab for DAAB 2.0. There I am trying to encrypt connection string and save it. The code snippet is as below:
static void ProtectConfiguration()
// TODO: Protect the Connection Strings
string provider = "RsaProtectedConfigurationProvider";
Configuration config = null;
config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.ConnectionStrings;
if ((section.ElementInformation.IsLocked == false) && (section.SectionInformation.IsLocked ==false))
section.SectionInformation.AllowDefinition = ConfigurationAllowDefinition.Everywhere;
section.SectionInformation.ForceSave = true;

But nothing happens when the code executes. Please let me know what is the problem. It gets successfully saved with emcrypted info when I say "SaveAS".

Thanks in advance.
Mar 22, 2007 at 2:25 PM
So the problem is not with the hands on lab, you are having a problem programmatically encrypting the connectionStrings Section?

I wrote an article on that some time ago that you can read here:

Encrypt Connection Strings AppSettings and Web.Config in ASP.NET 2.0 - Security Best Practices




David Hayden
Microsoft MVP C#
Jun 2, 2007 at 8:51 PM

Your code is ok, David, but I have the same problem that dmaster in gotdotnet (I have encrypted the connection string information in my app.config, but when I deploy the app I get an error "RsaProtectedConfigurationProvider"... because the RSA key container cannot be found.)

The problem is how to copy the app.config file in other machine to deploy it.

It is necessary export/import the rsa key?

Thanks in advance
Jun 5, 2007 at 2:39 AM
Here is more information about RSA:




David Hayden
Microsoft MVP C#
Jun 5, 2007 at 11:36 AM
Sorry, David, but I don't found Aspnet_regiis.exe in my computer.

I work with Visual Studio 2005 Professional.

If I develop a Windows Forms Application, it is necessary that file?

Any solution for to use "RsaProtectedConfigurationProvider", Enterprise Library and Connectionstrings in the app.config?

Jun 5, 2007 at 2:40 PM
Aspnet_regiis.exe is typically located at "C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727". It will work with winforms or webforms.

The Enterprise Library 3.0 Visual Studio Configuration Editor will help you encrypt, but it won't help you manage containers.





David Hayden
Microsoft MVP C#