App.Config檔內容像這樣


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <connectionStrings>
    <add name="mydb" connectionString="my connection details" />
  </connectionStrings>
</configuration>

 

 

用寫程式的方式


 Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);


 SectionInformation SIF = config.ConnectionStrings.SectionInformation;


  if (SIF.IsProtected)
  {
      SIF.UnprotectSection();
  }
  else
  {
       SIF.ProtectSection("DataProtectionConfigurationProvider");
      //SIF.ProtectSection("RsaProtectedConfigurationProvider");
               
  }

            SIF.ForceSave = true;
            config.Save(ConfigurationSaveMode.Full);


            MessageBox.Show("ok");

 

 

 

不要用VisualStudio開,因為開了也沒用,去開Debug/Bin裡面的檔案

arrow
arrow
    全站熱搜

    welkingunther 發表在 痞客邦 留言(0) 人氣()