1

I have a database in Microsoft SQL Server Management Studio and wish to include this in a project I'm working on. Of course, I could just place the connection string with all the data in the C# program itself, but I wish to do it more secure if possible. I have looked at protected configuration and I'm using the following code from Microsoft: RsaProtectedConfigurationProvider. But when I try to encrypt app.config I get an exception at config.save(ConfigurationSaveMode.Full); with the following message Inner exception ConfigurationErrorsException: Invalid key value.

This is the app.config I use:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="database" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=database;User Id=username;Password=test"/>
  </connectionStrings>
</configuration>

To make sure that I have the proper right to encrypt the section I run the application with administrator rights by using the following code in app.manifest: <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

So my question is how can I protect the configuration and how can I access the configuration to make the connection with the database?

Community
  • 1
  • 1
wes
  • 379
  • 3
  • 15

0 Answers0