Iterate over connection strings in the App.Config file in VB.Net

I am trying to iterate all connection strings in App.Config using VB.net.

I would like to: 1. Get an account of all the connection strings 2. Put them on the list.

I tried using System.Configuration.ConfigurationSettings, but I don’t know exactly how to get the collection / listof connection strings.

The application is a WinForms VB.net.net 4.0 application.

+4
source share
1 answer

This should work:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load ' You need to add a reference to System.Configuration ' Uncomment to get the count: ' Dim count As Int32 ' count = Configuration.ConfigurationManager.ConnectionStrings.Count Dim current As Configuration.ConnectionStringSettings For Each current In Configuration.ConfigurationManager.ConnectionStrings ListBox1.Items.Add(current.Name) Next End Sub 

Note. Unless you have instructions in your app.config, you will probably also get LocalSqlServer, as defined by default in Machine.config.

+5
source

All Articles