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

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

问题描述

好的,我有两个 Web 项目 WebProject1 &网络项目2.两者都需要数据库连接,所以这一切都在一个名为 Common 的 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.

现在我的问题是目前两者的连接字符串是相同的,目前它被硬编码到 DB 类中(在 Common 项目中),但我想将其移出配置文件.

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.

我真的很想在 Common 项目中有一个配置文件,其中包含两个 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?

推荐答案

有几种方法可以做到:

  1. 将常用配置设置放入 machine.config 中,如下所示此处
  2. 将通用配置设置放在一个中央文件中,并链接到每个项目的 app.config 中,如此处
  3. 将配置设置存储在注册表中

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

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