Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

Accessing connection string section of app.config file when using Practices.Enterprise

$
0
0

We are using Practices.Enterprise to access out databases.  The databases are located on different servers.  In our app.config file, we reference the external file as follows:

  <enterpriseLibrary.ConfigurationSource selectedSource="File Configuration Source">    <sources>      <add name="File Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=24982f64befa8a92" filePath="\Applications\Global\Config\Global5_0.config"/>      <add name="System Configuration Source" type="Microsoft.Practices.EnterpriseLibrary.Common.Configuration.SystemConfigurationSource, Microsoft.Practices.EnterpriseLibrary.Common, Version=5.0.414.0, Culture=neutral, PublicKeyToken=24982f64befa8a92"/>    </sources>  </enterpriseLibrary.ConfigurationSource>

I would like to be able to access the connection strings in the app.config file that are loaded from the external files.  I have tried the usual ways to access these connection string:

        Dim map As ExeConfigurationFileMap = New ExeConfigurationFileMap()        map.ExeConfigFilename = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Assembly.GetExecutingAssembly().ManifestModule.Name + ".config")        Dim config As Configuration = ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None)

        For k As Integer = 0 To config.ConnectionStrings.ConnectionStrings.Count - 1
            SW.WriteLine(config.ConnectionStrings.ConnectionStrings(k).Name)
        Next

(SW is a streamwriter. In the code block, I am just printing out the names of the

connection strings.)

This connection string collection contains only one string but we have many connection string in the external file

Any sugesstions would be appreciated and I appreciate your taking the time to guide me.

David

Viewing all articles
Browse latest Browse all 31927

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>