machine.config problem

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I am trying to use machine.config to store database settings for a
connection wrapper class I am using as part of the data layer of an n-tier
system.

Have added the following section to my machine.config file

<appSettings>
<add key ="iSpexDatabaseType" value ="SQL"/>
<add key ="iSpexServer" value ="DEVANS1"/>
<add key ="iSpexUserID" value ="sa"/>
<add key ="iSpexPassword" value ="[password]"/>
<add key ="iSpexDatabase" value ="ISPEX"/>
</appSettings>

To access this I have the following C# code:

Configuration config = ConfigurationManager.OpenMachineConfiguration();

dbType = config.AppSettings["iSpexDatabaseType"];
server = config.AppSettings["iSpexServer"];
uid = config.AppSettings["iSpexUserID"];
pwd = config.AppSettings["iSpexPassword"];
db = config.AppSettings["iSpexDatabase"];

I am getting the following compile error on each of the latter 5 lines of
code:

Error 1 'System.Configuration.ConfigurationElement.this[System.Configuration.ConfigurationProperty]'
is inaccessible due to its protection level
C:\iSpex\SPXDatabaseSettings.root\SPXDatabaseSettings\SPXDatabaseSettings\Settings.cs 24 22 SPXDatabaseSettings

Reading around, I suspect this to be a security error of some sort, perhaps
connected with access to the machine.config file. Though if it is a security
problem, I would have thought it would have produced a run-time error, not a
compile error. Is this a matter of changing the security on the
machine.config file? If so, how can I assign the relevant privleges to an
incomplete assembly that is still being developed, and therefore cannot yet
be assigned to the GAC?

Cheers

Ian
 
is that what you need, to store these information in machine.config?!
if it is then it is up to you.
So, No need to do this line
Configuration config = ConfigurationManager.OpenMachineConfiguration();
just try this:
dbType = ConfigurationManager.AppSettings["iSpexDatabaseType"];
......

It will work as long as the key exists in the web.config or machine.config.
and I suggest to read this from msdn

I hope it helped you
ms-help://MS.MSDNQTR.v80.en/MS.MSDN.v80/MS.VisualStudio.v80.en/dv_fxnetstart/html/2c1be77f-4da5-401b-8139-70b1ee3240bc.htm
--
Muhammad Mosa
Software Engineer & Solution Developer
MCT/MCSD.NET
MCTS: .Net 2.0 Web Applications
MCTS: .Net 2.0 Windows Applications
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top