如何因不同工作地点的连接字符串 [英] How to vary connection string for different work locations

查看:165
本文介绍了如何因不同工作地点的连接字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个C#4.0,WPF 4.0,SQL 2008的项目,我就在家里和办公室工作。我每次用在其他问题中提出的建议视觉SVN刚刚安装的颠覆。我遇到的问题是数据库连接字符串是每个位置不同。

I am working on a C# 4.0, WPF 4.0, SQL 2008 project and I do work at home and in the office. I just setup SubVersion using Visual SVN per the recommendations found in other questions. The problem I am having is the connection string for the database is different for each location.

在家里,我有数据库我开发的系统,在办公室数据库我们的服务器上。无论是暴露在网上,所以我不得不同时使用。有一种优雅的方式来自动选择正确的?

At home I have the database on my dev system, in the office the database is on our server. Neither is exposed to the internet so I have to use both. Is there an elegant way to automatically select the correct one?

更新

我一直有这个问题,正在进行和我试图平衡与我的项目完成工作学习的版本控制。我一直在读的书颠覆和上午罚款什么它涵盖。我唯一真正的问题是处理那些需要开发环境之间有所不同的文件正确的。我可以很容易地编写我的方式解决这个,但似乎有点古怪给我。我看到超过有关如何古怪了svn一对夫妇的文章:排除可能是,似乎我什么工作在家导致在工作,反之亦然问题

I have been having ongoing issues with this and am trying to balance learning version control with getting work done on my project. I have been reading the subversion book and am fine with what it covers. My one real issue is dealing with files that need to vary between development environments properly. I could easily code my way around this but that seems a bit wacky to me. I do see more than a couple articles about how wacky the svn:exclude can be and it seems to me that what works at home is causing issues at work and vice-versa.

也许我只是不知道足以识别正确的答案,请点我在正确的方向(我不需要你为我做的)或最多投票现有的最好的答案,我会继续我的研究。

Perhaps I just don't know enough to recognize the right answer so please point me in the right direction (I don't need you to do it for me) or up vote the best existing answer and I will continue my research.

感谢这么

推荐答案

如果你真的想完全自动化这个,你可以做这样的事情:

If you really want to automate this fully, you could do something like this:

首先,保存设置为源代码控制不同的环境,而不是实际的配置文件。例如:

First, store the settings for the different environments in source control, but not the actual configuration file. For example:

configfiles\app.config.mikeb_home
configfiles\app.config.local
configfiles\app.config.development
configfiles\app.config.staging
configfiles\app.config.production

然后在你的构建配置,你可以添加一个步骤,以正确的配置文件复制到根的app.config。例如。以预生成事件基础上的环境参数(计算机名,用户名,...)(命令行脚本)。您可以通过在.csproj的文件中添加一些的MSBuild命令可能达到同样的事情。

Then in your build configuration, you can add a step to copy the right config file to your root app.config. E.g. with a 'pre-build event' (command line script) based on 'environment' parameters (computername, username, ...). You can probably achieve the same thing by adding some msbuild commands in the .csproj file.

然而,这一切真的值得吗? TortoiseSVN也有一个功能叫做忽略上提交名单,它可以帮助您防止无意中犯了局部改动过的文件不应该犯(在提交对话框,在该文件=>移动右键单击要更改列表 - >忽略上提交)。可能是有点恼人,如果你确实需要更改config文件别的东西,但仍。

However, is all this really worth it? TortoiseSVN has a feature called the 'ignore-on-commit' list, which helps you prevent accidently committing a locally changed file that shouldn't be committed (in the commit dialog, right-click on the file => Move to Change List -> ignore-on-commit). May be slightly annoying if you actually need to change something else in the .config file, but still.

这篇关于如何因不同工作地点的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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