How to save program settings, database or configuration file?

Asked

Viewed 808 times

7

In my application, the admin user, can make some settings, for example:

  • Configure if you want to use specific product templates, or stay open for the end user to type.
  • Configure if you want to use TYPE table, or if the NCM will be open for the end user to type.

These are settings that will affect the entire system, and change the logic of the processing. Today I keep these set's, in the app.config, but I’ve been wondering, it would be the best way?

Maybe, save such settings in the bank and when performing the task I do a SELECT before to check how this configured?

Or not, the app.config is really for that, as the name already says? I think!

Let’s imagine, an application that runs on the server, not on the local machine.

  • For this type of case, use in the database, for example, if you change the machine for some reason.. the data will be saved in the database.. and not on the computer, except on the computer only things needed locally, such as connection settings with the server, (IP, port)...

  • I understand, but let’s imagine an application that runs on a server...

  • In this case, I’ve used the app.config, today no longer use, usually create a configuration class and serializo it, because I have more control for example, some case I’ve passed, serialize fountain and color

2 answers

5


The best for you in this particular situation only you can say.

The app.config is used for general settings of how the application works. Normally it should not be used to configure specific operation. It is not always easy to determine what is one and what is another. Understand that it was not made to have frequent changes.

If you have a database I think most settings should be in it.

As far as I understand this information is very specific and are only useful if the database is available. I’ve done several systems like this and never even considered not putting in the database.

I can’t imagine in this case why put this in the configuration file. You might even need to do something just in the database, and without them in it, it would be difficult to accomplish. This information is domain specific and not application as a whole. It is a mistake to put in app.config.

Overall

What to put in the configuration outside the database:

  • what tells how to access the database directly or indirectly, which for obvious reasons can not be within itself (can be network information)
  • information that other applications or the execution environment need to access at some point
  • other situations that can give a good justification for there.

In the database you have this information more "protected". And you have more resources, even for audit and versioning.

In some cases if you do not want to put it in the database, you need to think about whether it is not the case to use a separate configuration file. I find it rare to need something like this.

Of course, if you use a library that requires setting there, you have no choice but to switch libraries :)

If the application does not have a database, of course this solution is not ideal.

There are those who use Sqlite as configuration file. If it is only for this, unless the configuration is too complex, I do not think it is feasible. But if the Sqlite is already there for some reason, then it might be a good put in it.

If you only have the database on another machine it is possible that you wanted to use the same disconnected application. There is reason to use a configuration file. Or a local database like Sqlite, if you already use it for something else.

On the other hand if you want that user to have its settings preserved on all machines that you will use, putting the settings in a centralized database is the only option, although there may be a hybrid way to meet the disconnected cases.

It’s easier to do it right in the database.

The basic rule is to use the database, and only choose another way if you have a good reason to do so. But there should only be settings that are only needed when the database is available.

2

In my view, both app.config in Winforms and web.config in Webforms should be used for settings for system operation so that the system does not work without a certain configuration.

In your case, I believe this is parameterization. Different parameters make the system "think" differently. In that case, I would put such information in the bank. This way you can make screen to control such parameterization without having to touch the physical files of the system.

I’d do it that way.

  • Yes, I agree in parts.. in view, that even using the app.config, you can have a "screen" to control the parameterization.

  • Yes, it is possible. There goes what each one wants to do.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.