如何创建解决方案范围的连接字符串 [英] How do I create a Solution Wide Connection String

查看:44
本文介绍了如何创建解决方案范围的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道是否可以创建一个解决方案中的所有项目都可以访问的单个连接字符串(我们有大约 6 个).

Does anyone know if it is possible to create a single connection string that will be accessible to all the projects in a solution (we have about 6).

我可以用这些信息创建一个文本文件,但我们也需要设计时支持,在解决方案中的每个 App.Config 和 Web.config 文件中都有一个连接字符串是不切实际的.

I can create a text file with this information, but we need design time support as well, and it is not practical to have a connection string in every App.Config and Web.config file in the solution.

我们基本上想要一个单一的连接字符串,如果 db 的位置发生变化,它也很容易改变,IDE 也将使用它来支持设计时

We basically want a Single connection string that is easy to change should the location of the db change, that will also be used by the IDE for design time support

推荐答案

不确定,您不能将一个新的配置文件放到解决方案项中并在所有项目中包含并加载它吗?

Not sure, can't you just put a new config file to the solution items and include and load it in all projects?

我特指通用 (XML) 配置文件,而不是App.config".Is 具有完全相同的格式,只是名称不同.将此文件添加到您的解决方案项并使用 OpenMappedExeConfiguration.您可以在此处找到其他示例.

I am specifically talking about a general (XML) config file, not an "App.config". Is has exactly the same format, it just goes by a different name. Add this file to your solution items and access it using OpenMappedExeConfiguration. You can find an additional example here.

这篇关于如何创建解决方案范围的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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