Andrzej Gis
Andrzej Gis

Reputation: 14316

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)

Upvotes: 15

Views: 4245

Answers (2)

rohit poudel
rohit poudel

Reputation: 43

add it to gitignore file by right click inside git folder or we can get it from https://help.github.com/articles/ignoring-files/

Upvotes: 0

SLaks
SLaks

Reputation: 887797

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.

Upvotes: 27

Related Questions