Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent connection string from being committed to repository

I'm using GIT repository for my project. In my web.config I have a debug connection string to my local SQL server database. It won't work for anyone else. I cannot just put entire Web.config in .gitignore - the project wouldn't even compile.

A perfect solution would be to put the connection string in a separate file and make Web.config load it. Is it possible?

If not, is there any other solution? (using sql server CE won't work, because it breaks code first migrations)

like image 250
Andrzej Gis Avatar asked Aug 11 '13 02:08

Andrzej Gis


1 Answers

You can move a single section of Web.config to a separate file.

In Web.config, write

<connectionStrings configSource="connectionStrings.config" />

Then, move the original element to a separate connectionStrings.config (or any other filename) and add it to gitignore.

like image 135
SLaks Avatar answered Nov 09 '22 23:11

SLaks