1

これがばかげた質問のように見える場合は申し訳ありません。

私のアプリケーションは接続文字列を使用して SQL Server 2008 データベースに接続し、Crystal Report を使用します。私のサーバーは混合認証モードを使用します。

問題は次のとおりです。app.configファイルには、誰にも見られたくない接続文字列 (ユーザー名とパスワード) が表示されます。

Data Source=.\SQLEXPRESS;Initial Catalog=ComplainsDb;Persist Security Info=false; User ID=abcde ;Password=MyPassword

助けてくれてありがとう。

4

1 に答える 1

3

プログラムの開始時に次のように呼び出す必要があります。

    void EncryptConnectionStringsIfNecessary()
    {
        var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        ConnectionStringsSection section = configFile.ConnectionStrings;
        if (section != null)
        {
            if (!section.IsReadOnly())
            {
                if (!section.SectionInformation.IsProtected)
                {
                    section.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
                    section.SectionInformation.ForceSave = true;
                    configFile.Save(ConfigurationSaveMode.Full);
                }
            }
        }
    }
于 2013-09-23T09:33:34.130 に答える