views:

168

answers:

7

I have some configuration values for an asp.net web app. They will be maintained by a system admin once the system goes live. Should I store these values in the database or in a config file? Is there a best practice for this sort of thing?

A: 

Depending on the context of the config information, you could choose to leave it in the web.config or you could create maintenance tables for it in the database. I would typcially keep things more backend specific, like connection strings, ftp locations, usernames/passwords(for the application, not user permissions) in the web.config though.

I normally keep more relative information that relates to the information in the database rather than the application itself, in the database.

This is all loosely based though and not always the case.

thismat
Updating the web.config causes IIS to recycle the site.
Aaron Palmer
Like I said, all depends on the context.
thismat
A: 

I prefer to avoid databases if I can and I don't need the performance. If you need/have a database then I would say put as much as you can in one place. One thing to manage.

kenny
+8  A: 

It's easy and convenient to create a robust interface to edit the values in the database.

It's less easy to create a good one for the config file.

So I would usually you want to store everything which you would like your users/administrators to be able to edit later in the database. Everything which only needs to be touched during serious changes like re-installation etc is better off in the config file.

Ilya Kochetov
+3  A: 

I would always recommend database simply because you can build an Admin UI relatively easy and audit all changes with similar ease. Although you can accomplish the same with changes to a file, the database route with some sort of a Admin control area is always preferable. Especially when you want to know who changed what when.

Also in our environment, changing a config file if there was an error, involves the entire change management process approvals/etc., which is pretty painful. So if you take the time to incorporate configuration settings in a database I think it will work out better in the long run. Just my $0.02.

RandomNoob
A: 

I prefer a text config file, .ini style or XML style for these two reasons:

1 - You can put comments in the text file.

2 - Text editors have an "undo" command.

Corey Trager
A: 

I think databases are a great place for configuration values for distributed applications where you want a users settings to be available to them no matter which computer they use.

Configuration values stored in files are very useful for computer specific configurations (such as if you use a mapped drive to identify a location and every user may have a different mapping, like a CD/DVD drive for instance).

If you don't already have a database for the application you're developing though, it might be overkill to have a database exclusively for application configuration.

JettGeek
A: 

I prefer a text .ini file. They are easy to edit, and easy to move around when your application moves around. Here's an example Setting class that you may find useful.

Protagonist