Skip to content
Advertisement

How to vary connection string for different work locations

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?

Update

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.

Thanks SO

Advertisement

Answer

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:

configfilesapp.config.mikeb_home
configfilesapp.config.local
configfilesapp.config.development
configfilesapp.config.staging
configfilesapp.config.production

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.

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.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement