all groups > vb.net controls > july 2006 >
You're in the

vb.net controls

group:

Problem with user control and application/user settings


Problem with user control and application/user settings GAZ
7/22/2006 12:00:00 AM
vb.net controls: 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="SQLConnectionString" value="some value" />
</appSettings>

<userSettings>
<Test_Control_Library.My.MySettings>
<setting name="UserSQL" serializeAs="String">
<value>User</value>
</setting>
</Test_Control_Library.My.MySettings>
</userSettings>


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

System.Configuration.ConfigurationSettings.AppSettings("SQLConnectionString")

However, what we really need to get is the value stored in the UserSQL
setting under <userSettings> and 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

Re: Problem with user control and application/user settings GAZ
7/24/2006 1:14:04 PM
Got the solution:

In my application I added:

Dim config As System.Configuration.Configuration =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
config.AppSettings.Settings.Add("SQLConnectionString", "The-Conn-String")
config.Save(System.Configuration.ConfigurationSaveMode.Modified)
ConfigurationManager.RefreshSection("appSettings")

And in my control:

_SQLConnectionString =
System.Configuration.ConfigurationSettings.AppSettings("SQLConnectionString")


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

BR,

GAZ



[quoted text, click to view]

AddThis Social Bookmark Button