zoukankan      html  css  js  c++  java
  • C# read dll config

    public static SqlConnection GetSqlConnection()
            {
                Configuration myDllConfig =
                ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
                // Get the appSettings section
                AppSettingsSection myDllConfigAppSettings =(AppSettingsSection)myDllConfig.GetSection("appSettings");
                string connString = myDllConfigAppSettings.Settings["SQLConnString"].Value;
                SqlConnection connection = new SqlConnection(connString);
                return connection;
            }

     1.Right click on the *.config file in the dll project,then select Properties,as the below snapshot illustrates.

     2.Set 'Copy to Output Directory' as 'Copy Always';

     3.Rebuild Dll project and rebuild the Solution.

    Configuration myDllConfig =
    ConfigurationManager.OpenExeConfiguration(this.GetType().Assembly.Location);
    // Get the appSettings section
    AppSettingsSection myDllConfigAppSettings =
    (AppSettingsSection)myDllConfig.GetSection("appSettings");

    string connString = myDllConfigAppSettings.Settings["SQLConnString"].Value;

  • 相关阅读:
    主成分分析法
    K-means算法
    高斯混合模型
    data structure test
    八皇后问题求解
    商品管理系统课程设计
    哈佛商学院20部必看电影
    usaco1.1
    Visual Studio 2012 出现关于ActivityLog.xml错误的解决方案
    2012蓝桥杯决赛题
  • 原文地址:https://www.cnblogs.com/Fred1987/p/11431731.html
Copyright © 2011-2022 走看看