Configuration myDllConfig =
ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);
// Get the appSettings section
AppSettingsSection myDllConfigAppSettings =
(AppSettingsSection)myDllConfig.GetSection("appSettings");
string connString = myDllConfigAppSettings.Settings["SQLConnString"].Value;
原文:https://www.cnblogs.com/Fred1987/p/11431731.html