Problem with user control and application/user settings

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • GAZ

    #1

    Problem with user control and application/user settings

    Hello all,

    We have a bit of a problem with application settings and user control. In
    short, we have developed a user control that should, as it happenes, get a
    value stored in application settings of its host application. The app.config
    of the host application looks like this:

    <appSettings>
    <add key="SQLConnect ionString" value="some value" />
    </appSettings>

    <userSettings >
    <Test_Control_L ibrary.My.MySet tings>
    <setting name="UserSQL" serializeAs="St ring">
    <value>User</value>
    </setting>
    </Test_Control_Li brary.My.MySett ings>
    </userSettings>


    Now, our control can read the SQLConnectionSt ring value from <appSettings>
    by using:

    System.Configur ation.Configura tionSettings.Ap pSettings("SQLC onnectionString ")

    However, what we really need to get is the value stored in the UserSQL
    setting under <userSettingsan d we haven't got a foggiest how to do it. The
    reason behind using user settings is that the UserSQL value can change
    during the course of work and hence all controls should reflect that change.

    Any help would be greatly appreciated.

    BR,

    GAZ


  • GAZ

    #2
    Re: Problem with user control and application/user settings

    Got the solution:

    In my application I added:

    Dim config As System.Configur ation.Configura tion =
    ConfigurationMa nager.OpenExeCo nfiguration(Con figurationUserL evel.None)
    config.AppSetti ngs.Settings.Ad d("SQLConnectio nString", "The-Conn-String")
    config.Save(Sys tem.Configurati on.Configuratio nSaveMode.Modif ied)
    ConfigurationMa nager.RefreshSe ction("appSetti ngs")

    And in my control:

    _SQLConnectionS tring =
    System.Configur ation.Configura tionSettings.Ap pSettings("SQLC onnectionString ")


    Somewhat awkward solution, could've been a bit simpler but there we go.

    BR,

    GAZ



    "GAZ" <gaz@gaz.comwro te in message
    news:%23uUgT%23 WrGHA.4944@TK2M SFTNGP04.phx.gb l...
    Hello all,
    >
    We have a bit of a problem with application settings and user control. In
    short, we have developed a user control that should, as it happenes, get a
    value stored in application settings of its host application. The
    app.config of the host application looks like this:
    >
    <appSettings>
    <add key="SQLConnect ionString" value="some value" />
    </appSettings>
    >
    <userSettings >
    <Test_Control_L ibrary.My.MySet tings>
    <setting name="UserSQL" serializeAs="St ring">
    <value>User</value>
    </setting>
    </Test_Control_Li brary.My.MySett ings>
    </userSettings>
    >
    >
    Now, our control can read the SQLConnectionSt ring value from <appSettings>
    by using:
    >
    >
    System.Configur ation.Configura tionSettings.Ap pSettings("SQLC onnectionString ")
    >
    However, what we really need to get is the value stored in the UserSQL
    setting under <userSettingsan d we haven't got a foggiest how to do it.
    The reason behind using user settings is that the UserSQL value can change
    during the course of work and hence all controls should reflect that
    change.
    >
    Any help would be greatly appreciated.
    >
    BR,
    >
    GAZ
    >

    Comment

    Working...