Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Two different connection strings for web.config in Git

I'm fairly new to Git and I'm currently migrating a project that was in SVN to Git. The way that it currently works is that there is a dev directory on the server and a production directory on the server. Dev and production each have a separate database and thus have a different connection string in their respective web.config's. I'm going to be using the gitflow workflow so I'll be merging dev into master when changes are ready for production so I'll somehow need to have the web.config on the dev branch have one connection string and have a separate connection string on the production branch. Is there any logical way of doing this?

like image 947
Tony Barsotti Avatar asked Jun 27 '14 19:06

Tony Barsotti


People also ask

Is it safe to store connection string in web config?

The connection strings are mostly stored in web. config. It means that connection specific information such as database name, username, and password are stored as a clear text in a file. This is definitely a security concern for your Production servers.

What are the different parts of a connection string?

The Connection String includes parameters such as the name of the driver, Server name and Database name , as well as security information such as user name and password.


1 Answers

In asp.net you may want to look into web.config transformation. There's probably already a web.release.config and a web.debug.config in you project. They can be used to switch the connection string depending on which build configuration (build, debug, etc) you use to build your application.

Another idea which I've run into is including your connection strings in a separate file like:

<configuration>  
    <connectionStrings configSource="connectionStrings.config" />
</configuration>

which would cause .NET to load the connection strings from the connectionStrings.config file. Then that file is ignored in version control, and the dev version is distributed in the local development environments, the staging version is placed on the staging server and then the production one stays in production.

There are definitely more solutions than just these out there. But I've had decent luck with both of these options in a smaller gitflow type environment.

like image 114
Steven V Avatar answered Oct 28 '22 16:10

Steven V