1

Sorry if this looks like a stupid question.

My application uses a connection string to connect to a SQL Server 2008 database and uses Crystal Report, my server use mix authentication mode.

The problem is: app.config file shows connection string (user name & password) which I don't want anyone to see!

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

Thanks for any help.

marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
E.S
  • 536
  • 1
  • 9
  • 20

1 Answers1

3

You need to call something like this when your program starts:

    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);
                }
            }
        }
    }
shamp00
  • 10,837
  • 4
  • 34
  • 77