How to save program, database, or configuration file settings?

4

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

  • Set whether you want to use certain product templates, or leave it open for the end user to type.
  • Configure whether to use TIPE table, or whether NCM will be open for the end user to type.

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

Maybe, write such settings in the database and when executing the task I make a SELECT before to verify how it is configured?

Or does not app.config really do this, as the name already says? I think!

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

    
asked by anonymous 18.10.2016 / 12:19

2 answers

4

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

app.config is used for general application settings. It should not normally 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 meant 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 only useful if the database is available. I've done a lot of systems like this and never even thought about putting it in the database.

I can not imagine in this case why putting this in the configuration file. It may even be that you need to do something only in the database and without them inside it, it would be tricky to accomplish. This information is domain-specific and not the application as a whole. It is a mistake to app.config .

Overall

What to put in the configuration outside the database:

  • what tells you how to access the database directly or indirectly, which for obvious reasons can not be inside the database (can be network information)
  • Information that other applications or the runtime environment need to access at some point
  • situations that can give a good reason to go there.

In the database you have this more "protected" information. And it has more features, even for auditing 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 of using a separate configuration file. I find it rare to need something like this.

Obviously, if you use a library that requires setting up there, you have no choice but to switch library:)

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

Some people use SQLite as the configuration file. If it's just for that, unless the configuration is too complex, I do not think it's feasible. But if SQLite is already there for some reason, then it might be a good thing to put it in.

If you only have the database on another machine you might want to use the same application offline. There is reason to use a configuration file. Or a local database like SQLite, if you already use it for something.

On the other hand, if you want that user to have their configurations preserved on all machines that go to use, placing the settings in a centralized database is the only option, although there may be a hybrid way to handle disconnected cases.

It's easier to do right in the database.

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

    
18.10.2016 / 13:32
2

In my understanding, 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 certain configuration.

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

I would do it that way.

    
18.10.2016 / 12:27