' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
Imports System
Imports System.Configuration

Namespace E
    Public Class Program
        Public Shared Function GetConStr(con As String) As String
            Return ConfigurationManager.ConnectionStrings(con).ConnectionString
        End Function
        Public Shared Sub SetConStr(con As String, constr As String)
            Dim cfg As Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
            cfg.ConnectionStrings.ConnectionStrings(con).ConnectionString = constr
            cfg.Save(ConfigurationSaveMode.Modified)
            ConfigurationManager.RefreshSection("connectionStrings")
        End Sub
        Public Shared Sub Main(args As String())
            Console.WriteLine(GetConStr("Test"))
            SetConStr("Test", "bla bla bla")
            Console.WriteLine(GetConStr("Test"))
        End Sub
    End Class
End Namespace
