分享多个Web项目之间的连接字符串 [英] Share a Connection string between multiple web projects

查看:188
本文介绍了分享多个Web项目之间的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OK我有两个Web项目WebProject1&安培; WebProject2。这都需要数据库连接,所以这是所有常见的叫一个C#.NET项目。

OK I have two web projects WebProject1 & WebProject2. Both require database connectivity so this is all in a C#.NET project called Common.

现在我的问题是目前双方的连接字符串是相同的,目前很难coded到DB类(在共同的项目),但我想将其移动到一个配置文件。

Now my question is currently the connection string for both is the same and at the moment it's hard coded into the DB class (In the Common project), but I want to move it out to a config file.

我真的很想有与连接字符串,其中两个Web项目,然后使用通用项目配置文件。这是可能的,如果又如何?

I would really like to have a config file in the Common project with the connection string in which both web projects then use. Is this possible, and if so how?

推荐答案

有是你能做到这一点的几个方面:

There's a few ways you could do it:


  1. 把常见的配置设置在machine.config中所示这里

  2. 如图所示
  3. 把常见的配置设置在中央文件,并链接到每个项目的app.config中这里

  4. 存储在注册表中的配置设置

这篇关于分享多个Web项目之间的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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