Hi Harry,
data in the app.config isn't readonly at all! It can be accessed through the
configurationmanager-class (but not by my.settings, that's right). Below you
find code I use to set the connection-string at runtime. Be aware of the
fact, that you can use more than one connectionstring in your config, hence
the SectName.
Public Shared Sub SetConnectString(ByVal SectName As String, ByVal
ConnectString As String, ByVal encrypt As Boolean)
Dim settings As New ConnectionStringSettings
settings.Name = SectName
settings.ConnectionString = ConnectString
Dim config As Configuration
config =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
config.ConnectionStrings.ConnectionStrings.Remove(SectName)
config.ConnectionStrings.ConnectionStrings.Add(settings)
If encrypt Then
config.ConnectionStrings.SectionInformation.ProtectSection(Nothing)
End If
config.Save()
End Sub
HTH
Volker