Questions

Answer for:

Saving ASP web application configuration in SQL database

Message 2 of 5

View entire thread
+
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.