Best way to load/store web site settings in database

Discussion in 'ASP .Net' started by Max, Dec 8, 2003.

  1. Max

    Max Guest

    This is the best method I've found to store and load settings from database.
    I load the settings once at start as public variables. The method can be
    called easily anytime you want to load the new settings from database.
    Comments very welcome... I'd like to refine this... besides the error
    handling I need to add for the db conn...

    Global.asax ---------------
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    Dim oAppConfig As New myWebAppName.AppConfig
    oAppConfig.LoadSettings()
    End Sub

    AppConfig Class -------------------
    Public Class AppConfig
    Public Sub LoadSettings()
    Dim strConnectionString = "hardcode here or use the web.config"

    'some db code here...
    AppVars.strMailTo = 'get from database code here
    AppVars.strCompanyName = 'get from database code here
    AppVars.strSomeOtherVar = 'get from database code here
    'and so on...
    End Sub
    Public Sub StoreSettings()
    'same idea here...
    End Sub
    End Class

    AppVars Module - still debating on whether to use public class or module
    since they are the same thing...
    ----------------------
    Module AppVars
    Public strMailTo
    Public strCompanyName
    Public strSomeOtherVar
    End Module


    -Max
     
    Max, Dec 8, 2003
    #1
    1. Advertising

  2. Max

    Mythran Guest

    "Max" <> wrote in message
    news:be%Ab.28500$...
    > This is the best method I've found to store and load settings from database.
    > I load the settings once at start as public variables. The method can be
    > called easily anytime you want to load the new settings from database.
    > Comments very welcome... I'd like to refine this... besides the error
    > handling I need to add for the db conn...
    >
    > Global.asax ---------------
    > Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    > Dim oAppConfig As New myWebAppName.AppConfig
    > oAppConfig.LoadSettings()
    > End Sub
    >
    > AppConfig Class -------------------
    > Public Class AppConfig
    > Public Sub LoadSettings()
    > Dim strConnectionString = "hardcode here or use the web.config"
    >
    > 'some db code here...
    > AppVars.strMailTo = 'get from database code here
    > AppVars.strCompanyName = 'get from database code here
    > AppVars.strSomeOtherVar = 'get from database code here
    > 'and so on...
    > End Sub
    > Public Sub StoreSettings()
    > 'same idea here...
    > End Sub
    > End Class
    >
    > AppVars Module - still debating on whether to use public class or module
    > since they are the same thing...
    > ----------------------
    > Module AppVars
    > Public strMailTo
    > Public strCompanyName
    > Public strSomeOtherVar
    > End Module



    Best way ... to me this sounds like you should be using the Session object to
    store the values instead of your own class. You can use your own class, but it
    goes out of scope after every page load while the Session object does not.

    Mythran
     
    Mythran, Dec 8, 2003
    #2
    1. Advertising

  3. Max

    Max Guest

    But my way is in the application scope. A public class makes variables
    available to all users on the web site. As long as I only store a few
    strings -- 20 or 30, it should not use many resources. But your idea, in the
    session state, every user would have their own set of variables created,
    which would use a lot more memory!

    Plus if I wanted to change the web site's settings, I want the new settings
    to be available to all users currently on my site, without having every
    session load up new variables, and without the application restarting
    (losing everyone's session entirely).

    Am I right? Is there a better way? I think not. ;)

    -Max


    "Mythran" <> wrote in message
    >
    > Best way ... to me this sounds like you should be using the Session object

    to
    > store the values instead of your own class. You can use your own class,

    but it
    > goes out of scope after every page load while the Session object does not.
    >
    > Mythran
    >
    >
    >
     
    Max, Dec 8, 2003
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Chris Dunaway

    Where to store config settings in Web Service

    Chris Dunaway, Jan 9, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    583
    Curt_C [MVP]
    Jan 9, 2004
  2. leeanne
    Replies:
    0
    Views:
    1,877
    leeanne
    Sep 24, 2008
  3. donet programmer
    Replies:
    3
    Views:
    1,553
    Gregory A. Beamer
    Nov 20, 2009
  4. Luis Esteban Valencia

    Best Way to store simple data with web service?

    Luis Esteban Valencia, Jan 17, 2005, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    140
    Luis Esteban Valencia
    Jan 17, 2005
  5. Steve
    Replies:
    0
    Views:
    146
    Steve
    Mar 23, 2006
Loading...

Share This Page