Questions

Saving ASP web application configuration in SQL database

+
0 Votes
Locked

Saving ASP web application configuration in SQL database

scantoria
I am in the process of building a simple web app for our company. I have a friend that mentioned about saving the application configuration in a database.

Please explain this concept or point out some sites that will give me more information about this technique.

Thanks,
Steve
  • +
    0 Votes
    BOUND4DOOM

    I do not know is your after something specific, but you basically create a table in the database with 2 columns, set one as a identy column use nvarchar(255) as the data type, set the other column as ntext. The Identity becomes your Key and the Ntext becomes your value, this works just like a hashtable or any other dictionary type collection object. Then just create a couple methods in a common include file one called getconfig, one called set config. Those set and get your values from your table so anytime you want a value from the database. You call getconfig("KeyName") to set a value you call setconfig("KeyName","Value").

    If you really want to get fancy and get performance then acahe the config values in the application variables section of your site, so then when you call getconfig it check to see if the value is in memory before going to the database which is a lot faster, if it is not in memory then get the value from the database and put it in memory before returning it to you. Simple as that, similar to any hash table or dictionary collection. I do not know of any sites that show this though. This is really just basic dictionary collection style stuff.

    +
    0 Votes
    ward

    I like Doom's method, and have used it many times. In fairness I thought I should mention another approach. The configuration section of .NET can be descended from/overridden to read/write from anything you can write the code for. There is an article on MSDN about using this approach.

    +
    0 Votes
    BOUND4DOOM

    This way is much better, in reality I would create custom config handlers and using config sections for what you are wanting and go from there. Using web config in a .net environment is a much prefered aproach. I guess we would need clarification if this is ASP or ASP.net.

    I much prefer the web.config in .net because it is easy to work with and edit randomly like a developer might want to. Plus all the config information can be writen right out in a trace so you can see what is going on at the time. This really helps trouble shooting things. But if you are going with Classic asp. I would go with my previous post.

    +
    0 Votes
    Reality-based

    If the only need is for backup, and this is old ASP not ASP.net, then you have an option to backup the metabase.

    If your ASP site has a non-flat tree structure, that doesn't translate directly to a keyword=value list, you need a way to represent the branching.

  • +
    0 Votes
    BOUND4DOOM

    I do not know is your after something specific, but you basically create a table in the database with 2 columns, set one as a identy column use nvarchar(255) as the data type, set the other column as ntext. The Identity becomes your Key and the Ntext becomes your value, this works just like a hashtable or any other dictionary type collection object. Then just create a couple methods in a common include file one called getconfig, one called set config. Those set and get your values from your table so anytime you want a value from the database. You call getconfig("KeyName") to set a value you call setconfig("KeyName","Value").

    If you really want to get fancy and get performance then acahe the config values in the application variables section of your site, so then when you call getconfig it check to see if the value is in memory before going to the database which is a lot faster, if it is not in memory then get the value from the database and put it in memory before returning it to you. Simple as that, similar to any hash table or dictionary collection. I do not know of any sites that show this though. This is really just basic dictionary collection style stuff.

    +
    0 Votes
    ward

    I like Doom's method, and have used it many times. In fairness I thought I should mention another approach. The configuration section of .NET can be descended from/overridden to read/write from anything you can write the code for. There is an article on MSDN about using this approach.

    +
    0 Votes
    BOUND4DOOM

    This way is much better, in reality I would create custom config handlers and using config sections for what you are wanting and go from there. Using web config in a .net environment is a much prefered aproach. I guess we would need clarification if this is ASP or ASP.net.

    I much prefer the web.config in .net because it is easy to work with and edit randomly like a developer might want to. Plus all the config information can be writen right out in a trace so you can see what is going on at the time. This really helps trouble shooting things. But if you are going with Classic asp. I would go with my previous post.

    +
    0 Votes
    Reality-based

    If the only need is for backup, and this is old ASP not ASP.net, then you have an option to backup the metabase.

    If your ASP site has a non-flat tree structure, that doesn't translate directly to a keyword=value list, you need a way to represent the branching.