Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 348
Mike B Avatar asked Dec 22 '22 05:12

Mike B


2 Answers

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

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.

like image 189
jeroenh Avatar answered Jan 18 '23 22:01

jeroenh


Simple: Don't put the connection string in code, read it from configuration data somewhere. And then just don't put that configuration data in Subversion.

In an app that I'm working on now, we store connection string information in the Windows registry, in HKLM\Software\[OurProduct]\Database.

like image 36
Daniel Pryden Avatar answered Jan 19 '23 00:01

Daniel Pryden