[Mono-aspnet-list] Loading a ConnectionString from web.config instead of Assembly's app.config

Ferdinand Funke dr_doom1983 at yahoo.de
Wed Oct 26 07:53:14 EDT 2011


Hi,
I need to load a ConnectionString from my web.config. The problem is 
that another Assembly has to access the ConnectionString. So I created a 
second project which loads the ConnectionString in its AppDomain. This 
way I can configure ConnectionString once in web.config for the loader 
assembly and let the web project and the assembly access it through the 
loader. This works fine under .NET. But when I try to use it on Mono the 
loader assembly always tries to load it from its own AppDomain and 
therefore from its app.config.

This is my configuration in the web.config:

<configuration>
<configSections>
<sectionGroup name="applicationSettings" 
type="System.Configuration.ApplicationSettingsGroup, System, 
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="Utilities.Properties.Settings" 
type="System.Configuration.ClientSettingsSection, System, 
Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 
requirePermission="false"/>
</sectionGroup>

...

<connectionStrings>
<add name="Utilities.Properties.Settings.DBConnectionString" 
connectionString="Data Source=orcl;User Id=scott;Password=tiger;" 
providerName="System.Data.OracleClient"/>
</connectionStrings>

...

<applicationSettings>
<Utilities.Properties.Settings>
<setting name="DBConnectionType" serializeAs="String">
<value>Oracle</value>
</setting>
</Utilities.Properties.Settings>
</applicationSettings>
</configuration>

As you can see I load the ConnectionString from Properties. This is done 
in the loader project by this code:

public sealed class Settings
     {
         private Settings()
         {
             Common = new CommonSettings();
             if (string.IsNullOrEmpty(this.Common.DbConnectionString) || 
string.IsNullOrEmpty(this.Common.DbConnectionType))
             {
                 Load();
             }
         }
         private static volatile Settings instance = null;

         private static object m_lock = new object();

         public static Settings Instance
         {
             get
             {
                 if (instance == null)
                 {
                     lock (m_lock)
                     {
                         if (instance == null)
                         {
                             instance = new Settings();
                         }
                     }
                 }
                 return instance;
             }
         }

         public CommonSettings Common
         {
             get; set;
         }

         public void Load()
         {
             this.Common.DbConnectionString = 
Properties.Settings.Default.DBConnectionString;
             this.Common.DbConnectionType = 
Properties.Settings.Default.DBConnectionType;
         }
     }


This way I can access the ConnectionString from everywhere by this code:

Settings.Instance.Common.DbConnectionString

Well and that does not work on Mono. Does anyone here know a solution 
for that problem?

Best regards
Ferdinand


More information about the Mono-aspnet-list mailing list