在Silverlight项目中存储EF数据库连接字符串

发布于 2024-10-07 04:53:26 字数 679 浏览 0 评论 0原文

我们是一个由 4 名开发人员组成的团队,致力于同一个项目。我们使用实体框架来访问 SQL 数据库后端。我们将连接字符串存储在 web.config 中。

每个开发人员都针对自己的本地 SQL Server 数据库测试其代码。这意味着每个开发人员在 web.config 中都有自己的 SQL Server 连接字符串。我的计算机上通常有多个不同的数据库副本,其中包含来自不同场景的数据,我可以通过编辑连接字符串在这些副本之间进行切换。一个数据库可能是空的,另一个数据库可能包含大量测试数据等等。

我们面临的问题是,我们不小心将 web.config 定期签入源代码管理,这意味着当团队中的其他开发人员从源代码​​管理中检索最新代码时,他的本地 web.config - 以及他的连接字符串- 将被其他开发者的覆盖。 (顺便说一下,我们正在使用 AccuRev,其中没有好的方法可以忽略某些文件)。

我想到了几种不同的黑客解决方案:

  • 创建一个新的配置文件,我们在其中存储特定于计算机的配置。我们不会在源代码管理中签入此文件。或者我们使用其他名称来检查它。
  • 在源代码管理中将 web.config 重命名为 web.config.default (或其他名称)。从源代码管理中检出后,开发人员必须将 web.config.default 重命名为 web.config 才能运行。

当然必须有一些标准的方法来处理这个问题吗?

We're a team of 4 developers working on the same project. We use Entity Framework to access our SQL database backend. We store the connection string in web.config.

Each developer is testing his code towards his own local SQL server database. This means that each developer has his own SQL Server connection string in web.config. I typically have several different copies of the database on my machine, with data from different scenarios, which I switch between by editing the connection string. One database may be empty, another may contain huge amounts of test data and so on.

The problem we're facing is that we accidentally check in the web.config into source control regulary, which means that when one of the other developers on a team retrieves latest code from source control, his local web.config - with his connection string - will be overwritten with the one from the other developer. (We're using AccuRev by the way, in which there's no good way to ignore certain files).

I've thought of a couple of different hackish solutions:

  • Create a new configuration file, where we store computer-specific configurations. We don't check in this file in source control. Or we check it in using some other name.
  • Rename web.config to web.config.default (or something) in source control. After a checkout from source control, the developer has to rename web.config.default to web.config before he can run.

Surely there must be som standard way of handling this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

毅然前行 2024-10-14 04:53:26

如果您使用Visual Studio 2010,则可以使用web.config转换。

只是一个想法...
每个开发人员都需要设置自己的构建配置,例如 DebugDeveloperA、DebugDeveloperB、Staging、Relase 等...
Visual Studio 2010 为每个生成配置创建 web.config 转换文件,因此如果您从源代码管理获取最新版本,则需要确保使用您的生成配置。

if you use visual studio 2010, you can use the web.config transformation.

just a thought...
every developer need to set up his/her own build-configuration, like DebugDeveloperA, DebugDeveloperB, Staging, Relase, etc...
Visual Studio 2010 creates web.config tranformation files for every build configuration, so if you get the latest version from source control, you need to make sure, that you use your build configuration.

烟花肆意 2024-10-14 04:53:26

我采用了以下解决方案:

  • 在源代码管理中将 web.config 重命名为 web.config.default (或其他内容)。
  • 作为预构建步骤,检查 web.config 是否存在。如果没有,请将 web.config.default 复制到 web.config。

I went with the following solution:

  • Rename web.config to web.config.default (or something) in source control.
  • As a prebuild step, check if the web.config exists. If not, copy web.config.default to web.config.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文