Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    ' Get the file path for the current web request
    Dim webPath As String = Request.ApplicationPath

    'Parse the leading forward slash 
    webPath = webPath.Substring(0, webPath.LastIndexOf("/"))

    Try
        ' Get configuration object of the current web request
        Dim config As Configuration = _
     System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(webPath)

        ' Create new connection setting from text boxes
        Dim newConnSetting As New _
        ConnectionStringSettings(txtName.Text, txtValue.Text, txtProvider.Text)
    
        ' Add the connection string to the collection
        config.ConnectionStrings.ConnectionStrings.Add(newConnSetting)
    
        ' Save the changes
        config.Save()
    Catch cEx As ConfigurationErrorsException
        lblStatus.Text = "Status: " + cEx.ToString()
    Catch ex As System.UnauthorizedAccessException
        ' The ASP.NET process account must have read/write access to the directory
        lblStatus.Text = "Status: " + "The ASP.NET process account must have
        read/write access to the directory"
    Catch eEx As Exception
        lblStatus.Text = "Status: " + eEx.ToString()
    End Try

    ShowConnectionStrings()
End Sub
