使用通用的app.config或连接字符串 [英] Use common app.config or connect string

查看:105
本文介绍了使用通用的app.config或连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个解决方案,包括:
+项目1(P1):1个Windows窗体控制库(WFCL),1个数据集和1个app.config
+ P2:类似的P1
+ P3:是Windows窗体,我在P3中使用P1和P2
当我调试P3时,一切正常,尽管在P3中仍然没有app.config.
请大家为我创建 P3 的设置文件时帮助我解决2种情况,当我想更改连接字符串时,可以将其安装在任何系统中:
+ S1:P1和P2都使用公用数据库(仅数据库)
+ S2:P1使用P1的数据库,P2使用P2的数据库

请帮助我,
谢谢!

I have a solution include:
+ Project 1 (P1): 1 Windows Form Control Library (WFCL), 1 dataset and 1 app.config
+ P2: similar P1
+ P3: is windows form, i use P1 and P2 in P3
When i debug P3, all thing is ok although in P3 still have not app.config.
Pls everyone help me to solve 2 situation when i creat set up file for P3 and may be install in any system when i want to change connect string:
+ S1: both P1 and P2 using common database (only database)
+ S2: P1 use database of P1, P2 use database of P2

Pls help me,
Thanks!

推荐答案

我的应用程序不会引用多个配置文件.但是它可以具有多个设置文件,也可以在配置文件中具有多个部分.

在P3中进行应用配置.

使用设置文件(可以是p1Settings.settings).在此处输入您的连接字符串和其他设置.保存此设置后,您的应用程序配置将具有连接字符串.

当您引用其他DLL项目中的dll时(p3).右键单击->添加现有项,然后从库项目路径中选择p1Settings.setting文件.这会将设置文件添加到当前项目.将此文件移动到解决方案资源管理器中属性"部分下.打开此设置文件,然后在设计器中输入一个虚拟值并保存.现在,这些条目将追加到Form项目的(p3)配置文件中.

立即打开应用程序配置文件,您可以在此处看到设置文件中的所有设置.但是此p3项目名称的一件事是附加在所有设置的名称中.将其替换为您的图书馆项目名称.

现在,您的库读取了p3的应用程序配置,该配置提供与库中相同的设置.您可以在配置文件中编辑任何设置.

我认为这是您可以做的.如果库项目中的设置很少,则将其复制并粘贴到p3的应用程序配置中的相应部分.

在网上搜索是否有更好的解决方案.
I an app won''t refer to multiple config files. But it can have multiple settings file or may have multiple sections in the config file.

Have a app config in the P3.

Use a settings file (may be p1Settings.settings). Enter your connection strings and other settings here. Once you saved this your app config will have the connection strings.

When you reference then dll from other Form projects (p3). Right click ->Add Existing item, select the p1Settings.setting file from the library project path. This will add the settings file to the current project. Move this file under the properties section in the solution explorer. Open this settings file and enter a dummy value in the designer and save. Now these entries will be append to the Form project''s (p3) config file.

Open the app config file now, you can see all the settings from the settings file append here. But one thing this p3 projects name is append in all the setting''s name. Replace that with your library project name.

Now your library read the app config of p3 which provide the same settings as in the library. You can edit any settings in the config file.

I think that''s what you can do. If the settings in the library project are few then copy and paste those to the p3''s app config to the appropriate sections.

Search net if there is better solution available.


这篇关于使用通用的app.config或连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆