We help IT Professionals succeed at work.

Error when encrypting web.config database connection string

Rouchie asked
Medium Priority
Last Modified: 2012-05-05
The code below is supposed to encrypt the database connection string in web.config, however, when run it throws an error.  Can anyone shed any light on why such an error would occur??

Dim path as string = "/netdump"
Dim config as configuration = WebConfigurationManager.OpenWebConfiguration(path)
Dim appSettings as configurationSection = config.getSection("connectionStrings")
If order then
End If

- Error ----------------------------------------
Unable to save config to file 'c:\inetpub\wwwroot\netdump\web.config'.
Line 22:  config.Save()
Watch Question

where r u running this code from .. the same machine where the web server resides? is the file set as "read only" ...


The file isn't set as read only and it is on the same machine as the web server.  I've managed to work around the problem by setting the ASP.NET user account on the machine to have MODIFY access privileges to the file directly.  For some reason though, the FULL CONTROL box is ticked and also greyed out.  Not sure if this is an advisable way to proceed though from a security perspective.
once u have run the code to encrypt the connectionstring .. u can reset the permission of the file .. i assume u do not need this feature in the production environment .. right?

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts


I guess not.  So if I encrypt locally on my development machine, and then copy web.config across to the server, the server will be able to read it okay?
i assume it should work .. unless the encrypt logic uses some machine specific details .. u could give it a try ... haven't tried it myself ..

Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.