Search code examples
c#web-config

What Is The Best Practices For Database Connection String Management Among Multiple Applications


Currently, I have multiple applications that share the same DB connection string & the DB connection string stores in web.config file.

The issue I am facing now is I found extremely troublesome to update the DB connection string among the applications.

For example, there are 10 running applications, so there are 10 web.config files I have to update. Therefore, I have to open these 10 web.config files one by one and modify the DB connection string.

Is there any good practices or methods to ease the DB connection management for this scenario?


Solution

  • Try to get the variables you need from environment instead, there's a way to do it inside your web.config files too. Look this answer!

    Supposing that you're running the tens application on the same machine and they're sharing the same database you'll find easier to change the environment variables than updating manually every web.config file.

    Then if you want to have different env variables based on where you're application is executed give direnv a try.