为什么 App.config 只能从主项目中读取?
我有两个 C# 项目:
1. 一个 DAL 项目,由一个 sql Compact.e 数据库和一个 .cs 文件组成,该文件在从项目的 app.config 文件读取连接字符串后调用存储的过程。
2.一个客户端项目 - a简单的 .cs,使用 DAL 项目访问数据库并在简单的 GUI 中显示结果。
我遇到了 DAL 的一些问题,因为 ConfigurationManager.ConnectionString 一直为空
然后我发现如果我将连接字符串放入
客户端的app.config中,那么它可以读取它。
我有两个问题:
1. 为什么会这样?为什么驻留在 DAL 项目中的文件只能读取客户端项目的 app.config 文件,而不能读取自己的项目?
2. 将 app.config 添加到连接到同一个 DAL 项目(因此连接到同一个数据库)的每个客户端项目似乎相当愚蠢。如何让我的所有项目都拥有一个 app.config 文件?或者我如何确保 DAL 项目的 .cs 文件能够读取它自己的 app.config 文件?
提前致谢
I have two c# projects:
1. A DAL project which consists of a sql compact.e database and a .cs file that calls the stored procs
after reading the connection string from the project's app.config file.
2.A client project- a simple .cs that uses the DAL project to access the DB and display the results in a simply GUI.
I've ran into some issues with the DAL, since ConfigurationManager.ConnectionString was empty
all the time and then I discoverd that if I put the connection string inside the
client's app.config then it can read it.
I have two questions:
1. Why does it work that way? Why a file the resides inside the DAL project can only read the client's project app.config file and not it's own?
2. It seems rather silly to add app.config to each client project that connects to the
same DAL project, hence to the same DB. How can I have one app.config file mutual to all
of my projects? Or how can I make sure that the DAL project's .cs file will read it's
own app.config file?
Thanks ahead
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论