views:

159

answers:

4

Does anyone know of a technique to prevent someone (me!) accidentally committing a file with a public database connection string in it to Google Code. I need to run some unit tests on the database from my local machine (to update the DB schema) but I'm concerned that I'll forget that I've changed the connection to point to the public DB and then check the code into SVN.

Of course it's not likely to happen the first time but probably after 5 or 10 times.

What's the easiest way to handle this?

+2  A: 

I usually create a default config file called something like myapp.config.default, that doesn't contain any passwords, and add that file to the repository instead of my actual configuration file.

Emil H
+1  A: 

Allow your configuration data to be overridden by a local config file, some file in your home directory. Include in the application logic a heirarchy of locations for locating the config file.

basszero
+1  A: 

I second Emil H proposal with one addition: you should ignore via svn:ignore-property the correct configuration file

eg your config-file should reside on:

./config/app.conf

then you should ignore this file for subversion:

svn propset svn:ignore "app.conf" ./conf

and copy the app.conf to app.conf.example and add this file to subversion: cp app.conf app.conf.example svn add app.conf.example

Now Subversion will never try to add your app.conf file to your repository(and also your colleagues cannot accidentially commit this file!)

Peter Parker
+1  A: 

Here's the solution I use for a web app. First, I don't want to ignore the Web.config file in svn because it contains important information that can and will change. Thus, I pull the connection string out of the Web.Config, place it in a file called WebCS.config and then use the SVN .ignore directive to avoid checking in just that one file.

To do this, place the following "include" line in the Web.Config:

 <connectionStrings configSource="WebCS.config"/>

Then, create the WebCS.config file and enter the following:

<connectionStrings>
<add name="ConnString" 
         connectionString="Data Source=YourServer;Initial Catalog=YourDB;etc..
         providerName="System.Data.SqlClient"/>
</connectionStrings>

This also makes it easy to update web sites: just upload all but the WebCS.config file (I have a batch file to remove the file after "publishing" the site). You'll then be assured that all of the Web.Config file settings go with you without messing with your connection string AND you'll be assured that your repository isn't missing an important file AND you won't be exposing your connection string.

Mark Brittingham