Home All Groups Group Topic Archive Search About

Reading Config from custom location in .NET 2.0

Author
8 Jan 2007 6:28 AM
jboy
My company has recently purchased a software product that spans several
technologies (ASP, COM,  VB 6.0, .net 1.1, .net 2.0). We are trying to
standardize the software over to one technology (.net 2.0).  Part of
this is to locate general settings (such as database connection strings
etc...) into one central location.

I was able to do this for the asp.net 1.1 Web Site, Web Services and
console apps by setting the "file" attribute of the <appSettings>
section of the relevant Config file:- E.G

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings file="D:\Mydirectory\test.config" />
</configuration>


I have created a custom class in .NET 2.0 that reads data from my
custom config file, reading from the file such as this:-

Return
System.Configuration.ConfigurationManager.AppSettings["DatabaseConnString"].ToString();

However the problem lies when trying to use this code via COM+ so as
the ASP portion of the software can get its configuration details from
the same place.  As COM+ executes in it own container (I think under
dllhost.exe??) then using the above code to read a setting is obviosly
not going to work as there is no way to set the following :-
<appSettings file="D:\Mydirectory\test.config" />

What I was hoping I could do was in my custom class that gives out
configuration details, is to specify a path to where the configuration
data is stored (E.G D:\Mydirectory\test.config) and load that
configuration file into memory and read from it.  Does anyone know how
to specify the location of a .config file and load it into an object to
parse it for configuration settings???  Or perhaps someone knows of a
way by using .NET 2.0 technologies (such as property settings) that
configuration type data can easily be read from ASP via COM+.

Many thanks in Advance.

AddThis Social Bookmark Button