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;

C# read dll config的更多相关文章
- 获取指定DLL程序集Config 文件
/// <summary> /// 获取调用函数所在程序集的配置信息 /// </summary> /// <returns></returns> pr ...
- c# 如何使用DLL的config文件中的信息
我知道用c#编写的exe程序可以读取config文件中的配置信息,比如Test.exe,可以在与Test.exe相同目录下放置一个config文件:Test.exe.config,用System.Co ...
- asp.net中web.config配置节点大全详解
最近网上找了一些关于Web.config配置节点的文章,发现很多都写的都比较零散,而且很少有说明各个配置节点的作用和用法.搜索了一下发现有一篇写的不错,这里引用一下 原文地址 http://www.c ...
- web.config详解 -- asp.net夜话之十一
1.配置文件节点说明 1.1 <appSettings>节点 1.2 <connectionStrings>节点 1.3 <compilation> ...
- 浅谈config文件的使用
一.缘起 最近做项目开始使用C#,因为以前一直使用的是C++,因此面向对象思想方面的知识还是比较全面的,反而是因没有经过完整.系统的.Net方面知识的系统学习,经常被一些在C#老鸟眼里几乎是常识的小知 ...
- asp.net夜话之十一:web.config详解
转:http://blog.csdn.net/zhoufoxcn/article/details/3265141 在开发中经常会遇到这样的情况,在部署程序时为了保密起见并不将源代码随项目一同发布,而我 ...
- asp.net中web.config配置节点大全详解【转】
web.config 文件查找规则: (1)如果在当前页面所在目录下存在web.config文件,查看是否存在所要查找的结点名称,如果存在返回结果并停止查找. (2)如果当前页面所在目录下不存在web ...
- Web.config总结
%windir%/Microsoft.NET/Framework/v2.0.50727/CONFIG目录下machine.config定义了针对当前机器的WinForm程序和asp.net应用程序的配 ...
- 配置文件入门 - WebConfig.config常用配置节点介绍
一.配置文件入门 .Net提供了一种保存项目配置信息的办法,就是利用配置文件,配置文件的后缀一般是.config.在WinForm程序中配置文件一般是App.config.在Asp.net中一般默认是 ...
随机推荐
- Mac--ModuleNotFoundError: No module named 'magic'
关于Mac本报错“ ModuleNotFoundError: No module named 'magic' ” 作为一个python程序员,简单粗暴pip install python-magic ...
- 阿里钉钉技术分享:企业级IM王者——钉钉在后端架构上的过人之处
本文引用了唐小智发表于InfoQ公众号上的“钉钉企业级IM存储架构创新之道”一文的部分内容,收录时有改动,感谢原作者的无私分享. 1.引言 业界的 IM 产品在功能上同质化较高,而企业级的 IM 产品 ...
- Python time.time()方法
描述 Python time time()返回当前时间的时间戳. 时间戳:时间戳是指格林威治时间1970年01月01日00时00分00秒(背景时间1970年01月01日08时00分00秒)起至现在的总 ...
- Python调用Redis
#!/usr/bin/env python # -*- coding:utf-8 -*- # ************************************* # @Time : 2019/ ...
- 前端之HTML介绍及使用
一.HTML介绍 1.1 web本质 在pycharm写入一下代码,然后在浏览器地址栏输入地址和端口127.0.0.1:8080,回车,回来运行代码,直接访问客户端发送的内容conn.send(b'& ...
- C# loop executed one by one wait the former completed
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 去掉烦人的“!=null"(判空语句)
文章首发于公众号 松花皮蛋的黑板报 作者就职于京东,在稳定性保障.敏捷开发.高级JAVA.微服务架构有深入的理解 为了避免空指针调用,我们经常会看到这样的语句 if (someobject != nu ...
- 'Specifying a namespace in include() without providing an app_name '
'Specifying a namespace in include() without providing an app_name ’ 从include()函数可以看出来,这个函数有两个参数,一个a ...
- Python 获 Mozilla 和扎克伯格夫妇 40 余万美金资助
Python 软件基金会近日发文宣布,收到来自 Mozilla Corporation 和 Chan Zuckerberg Initiative(CZI)的资金赞助,共计 407,000 美元.这笔款 ...
- SSH整合二
结构图 articles模块 实体类Articles.java package com.jt.articles.entity; public class Articles { private Inte ...