3

situation

We use migrations to update the database schema and configuration files for all deployments of our web application. Now we have a problem with migrating the web.config.

current implementation

The migration process does the following:

  1. Open the database connection
  2. Read configuration from web.config into a configuration object
  3. Retrieve all migrations
  4. Iterate migrations
    1. Update database schema (database connection is passed as parameter)
    2. Update configuration object (configuration object is passed as parameter)
  5. Save configuration object
  6. Close database connection

Of course there is a lot of code that makes sure that the migrations are not screwing things up when something goes wrong. No worries there. Also restarting the webserver upon save the configuration is not a problem either.

problem

The problem is that it does not seem possible to make certain changes to the web.config through the configuration object. Like adding a location.

possible solution

My thoughts are now to not pass the configuration object, but the *.config files as a dictionary of xml documents. The migrations can then make changes to the raw xml.

worries

I am not too exited about this approach, because the configuration object does some configuration data integrity checks. This capability is lost when working with raw xml.

question

Is this the best approach?

RandomProgrammer
  • 1,570
  • 1
  • 14
  • 23

3 Answers3

2

I would not think on "Best approch". It's a continuous improvement.

I would validate dictionary of xml documents for integrity.

Saar
  • 8,286
  • 5
  • 30
  • 32
  • Validating the xml document is indeed a good idea! Thank you. What do you mean with continuous integration? Btw: no idea what the down vote is all about. – RandomProgrammer Nov 23 '09 at 19:38
1

Yes, one answer is to use XML directly, or reflection as discussed here. In the end, "do the simplest thing that could possibly work"...

Community
  • 1
  • 1
Jeremy McGee
  • 24,842
  • 10
  • 63
  • 95
0

There are few options:

  1. Use a windows forms program to modify web.config (this is the approach we have taken)

  2. See the following article: How do you modify the web.config appSettings at runtime?

Now changing web.config may restart the application domain. You can however stop that by disabling the runtime scanning.

Community
  • 1
  • 1
Samuel
  • 1,949
  • 4
  • 18
  • 30
  • Thank you for your swift answer. However, could you please elaborate on how your answer is related to my problem. – RandomProgrammer Nov 22 '09 at 22:20
  • I thought you wanted to change the web.config at runtime. – Samuel Nov 22 '09 at 23:09
  • That is true and that is not the problem. The problem is that the configuration class is partly 'readonly'. It does not seem to be possible to make all changes we need. Like adding a location. – RandomProgrammer Nov 23 '09 at 19:35
  • Yes we have currently done what you mention as the "possible solution". I will track this tread to see if somebody provides a different point of view. – Samuel Nov 24 '09 at 21:49