Digbyswift
Digbyswift

Reputation: 10410

When should I store config data in the database and not my web.config?

Normally, I would store all application configuration data in the web/app.config and associated xml configuration files. But I was thinking that maybe this wasn't necessarily the best way of handling all config data.

Are there any suggestions as to when it might be more practical to use one or the other?

Upvotes: 5

Views: 1678

Answers (3)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727047

I do not have a clear-cut rule, but my "rule of thumb" is to store locally only the configuration that is specific to the computer on which the program runs, and store all shared configuration data in a database.

We developed a small library for storing and editing/versioning our configuration in a database. We also designed a shared configuration store with separate areas for each application, and an ability to reuse config entries in multiple applications. We store high-level configuration entries, such as rules, query definitions, etc. in the database.

The location-specific configuration, such as locations of plugin assemblies, connection string for the DB-based configuration library, logging settings, etc. go into the "regular" web/app.config files. This lets us keep a relatively clean separation of local vs. shared configuration.

Upvotes: 4

Josh
Josh

Reputation: 10624

If you want to be able to change configuration values without restarting the web site, store them in the database. But this adds a layer of copmlexity that most developers, when looking for configuration values, would not look to first to find them. The standard, at least in my shop, is to put all values that might change in the web.config file, and encrypt them if necessary (credentials to third party services, databases, etc.) If someone were to put configuration values in the database, the developer, on the first dive into the code, would spend some time looking for where the configuration values are stored (but this is only a one-time thing, but still a nuisance).

Upvotes: 0

user596075
user596075

Reputation:

If the configuration contains sensitive data, and needs to have another layer of security (i.e. RDBMS security), then store configuration in the database. Conversely, if client administrators need easy and quick access, and aren't expected to hack the database with UPDATE commands, then it would be wise to keep config in a config file.

Upvotes: 3

Related Questions