1

我在 Microsoft SQL Server Management Studio 中有一个数据库,并希望将其包含在我正在处理的项目中。当然,我可以将连接字符串与所有数据放在 C# 程序本身中,但如果可能的话,我希望这样做更安全。我查看了受保护的配置,并且正在使用 Microsoft 的以下代码:RsaProtectedConfigurationProvider。但是,当我尝试加密 app.config 时,出现异常config.save(ConfigurationSaveMode.Full);并显示以下消息Inner exception ConfigurationErrorsException: Invalid key value.

这是我使用的 app.config:

<?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>

为了确保我有适当的权限加密我以管理员权限运行应用程序的部分,方法是在 app.manifest 中使用以下代码:<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />

所以我的问题是如何保护配置以及如何访问配置以与数据库建立连接?

4

0 回答 0