如何在引用的程序集中更改类型化数据集的连接字符串 [英] How do I change connection strings of typed dataset in referenced assembly
问题描述
我有一个应用程序和程序集。 App_1和ass_1。在ass_1中,有来自app_1或任何其他应用程序的表单和类型化数据集,因此可以从这些应用程序中调用ass_1中的表单和类。 app_1,app_xx等引用应用程序有自己的数据库连接,因此引用的程序集(ass_1)必须从引用应用程序(app_1)获取其连接字符串。 Ass_2将从GAC(共享)引用,以便不同的应用程序可以引用它。我如何在C#中解决这个问题。即。在运行时动态更改引用程序集的连接字符串。 NB :引用的程序集(ass_1)可能同时运行多个引用的实例,并且每个实例将具有来自引用应用程序(app_1)的自己的连接字符串。
要么:
1)从配置文件中读取连接字符串。
2)为程序集创建一个接口并传递连接作为这些程序集的参数。
连接永远不应该是代码的一部分。
从任何配置app.config / xml等读取它们。
I have an application and an assembly. App_1 and ass_1.In ass_1 there are forms and typed datasets referenced from app_1 or any other application so that forms and classes in ass_1 can be called from those apps ie. app_1,app_xx etc. the referencing apps have their own database connections so the referenced assembly (ass_1) has to get its connection string from the referencing app (app_1). Ass_2 will be referenced from GAC (shared) so that different apps can reference it. How do I go about this in C#. ie. dynamically changing connection strings of referenced assembly at runtime. NB: The referenced assembly (ass_1) may have more than one referenced instances runinng at the same time and each instance will have its own connection string from the referencing app (app_1).
Either :
1) Read the connection string from a configuration file.
2) Create an interface for your assemblies and pass the connection as a parameter to those assemblies.
Connections should never be part of code.
Read them from any configuration app.config/xml etc.
这篇关于如何在引用的程序集中更改类型化数据集的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!