473,748 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with config file

Ian
Hi,

Am having trouble retrieving a value from a config file using VC# 2005.

app.config file (as created using 'Settings' tab on Project properties page)
is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<sectionGroup name="applicati onSettings"
type="System.Co nfiguration.App licationSetting sGroup, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9" >
<section name="TestSQL.P roperties.Setti ngs"
type="System.Co nfiguration.Cli entSettingsSect ion, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9" requirePermissi on="false" />
</sectionGroup>
</configSections>
<applicationSet tings>
<TestSQL.Proper ties.Settings>
<setting name="SQLDataba se" serializeAs="St ring">
<value>server=( local);uid='sa' ;pwd=''</value>
</setting>
</TestSQL.Propert ies.Settings>
</applicationSett ings>
</configuration>

The code I am using to try to access the SQLDatabase value is:

AppSettingsRead er appReader = new AppSettingsRead er();
string conn = (string)appRead er.GetValue("SQ LDatabase", typeof(string)) ;

When the second line is executed, I get an InvalidOperatio nException saying
that "The key 'SQLDatabase' does not exist in the appSettings configuration
section."

Except it does exist. Cant see anything wrong - no problem with case even -
but I wonder about the namespace in the app.config file that encloses by
value. This corresponds with the default namespace for the project, which is
an ordinary WindowsApplicat ion.

Any idea why I am getting this problem?

Thanks

Ian

Jul 18 '06 #1
1 1844
Ian,
If you want to put the value in the appSettings section, you can do so easily:

<appSettings>
<add key="SqlDatabas e" value="server=( local);uid='sa' ;pwd='' />
</appSettings>

Read this with: ConfigurationMa nager.AppSettin gs["SqlDataBas e"];

You also have a connectionStrin gs section you can use for this.

Keep it simple if all you need is simple values.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Ian" wrote:
Hi,

Am having trouble retrieving a value from a config file using VC# 2005.

app.config file (as created using 'Settings' tab on Project properties page)
is as follows:

<?xml version="1.0" encoding="utf-8" ?>
<configuratio n>
<configSections >
<sectionGroup name="applicati onSettings"
type="System.Co nfiguration.App licationSetting sGroup, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9" >
<section name="TestSQL.P roperties.Setti ngs"
type="System.Co nfiguration.Cli entSettingsSect ion, System, Version=2.0.0.0 ,
Culture=neutral , PublicKeyToken= b77a5c561934e08 9" requirePermissi on="false" />
</sectionGroup>
</configSections>
<applicationSet tings>
<TestSQL.Proper ties.Settings>
<setting name="SQLDataba se" serializeAs="St ring">
<value>server=( local);uid='sa' ;pwd=''</value>
</setting>
</TestSQL.Propert ies.Settings>
</applicationSett ings>
</configuration>

The code I am using to try to access the SQLDatabase value is:

AppSettingsRead er appReader = new AppSettingsRead er();
string conn = (string)appRead er.GetValue("SQ LDatabase", typeof(string)) ;

When the second line is executed, I get an InvalidOperatio nException saying
that "The key 'SQLDatabase' does not exist in the appSettings configuration
section."

Except it does exist. Cant see anything wrong - no problem with case even -
but I wonder about the namespace in the app.config file that encloses by
value. This corresponds with the default namespace for the project, which is
an ordinary WindowsApplicat ion.

Any idea why I am getting this problem?

Thanks

Ian
Jul 18 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3986
by: Cartensy | last post by:
Hi, I try to configure a php applic to load a config file (the purpose is to use in all the php pages variables definied in a config file) Here is a small example which describe my problem: My config file (test_config.php) <? $FOO=1; print "IN REQUIRE FILE: $FOO\n"; ?>
2
2565
by: Senthoorkumaran Punniamoorthy | last post by:
I am printing these information. print string.lower(info_res) print string.lower(md5sum(f_md5)) print len(string.lower(info_res)) print len(string.lower(md5sum(f_md5))) print str(string.lower(md5sum(f_md5)) == string.lower(info_res)) and the output are
1
2569
by: timothy.williams | last post by:
I'm trying to install wxPython 2.5.3.1 using Python 2.3.2 on a Fedora 2 machine. I have python in a non-standard place, but I'm using --prefix with the configure script to point to where I have everything. The make install in $WXDIR seemed to go fine. I have the libxw* libraries in my lib/ directory libwx_base-2.5.so@ libwx_gtk_adv-2.5.so.3.0.0* libwx_base-2.5.so.3@ libwx_gtk_core-2.5.so@
2
2080
by: Eric Caron | last post by:
Hi Here's my problem, I create a windows service with Config.xml file. All setup for my service is in this file. I create a windows application to manage these settings (Config.XML File). This work good if the two applications are in the same folder and Config.XML is in the folder too but If not, my windows application setting don't work. In my windows form I have a Service controler components to manage my service (start, stop, ...)....
0
2241
by: Tomas Vera | last post by:
Hello All, I've developed a Commerce Server application and am having deployment problems. The issue is not Commerce Server specific, so I'll ask here, since questions get answered here. The application is developed on a remote machine. My compiler runs locally, but the source files and destination is on the remote machine. The remote machine is running Framework 1.0.3705. This morning I PUP'd the Commerce Server site and deployed it...
0
1501
by: Roy Chastain | last post by:
I have a simple page or two and a simple global.asax file that loads some configuration from the web.config file. I developed this on a Windows XP box with framework version 1.1 installed. I run it on a 2003 box with both version 1.0 and 1.1 installed. This appears to work. When move the page and code to my clients hosting service (Earthlink) which only supports version 1.0 of the framework, I get the error below. I know that my...
12
3276
by: Steven Berkovitz | last post by:
I have several ASP.NET applications with near identical web.config files. In one of them I am successfuly able to bind to an assembly while on others I am not. All of them have the following qualifiers: <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <qualifyAssembly partialName="OrderDynamics.ImageService.Interfaces"...
7
1399
by: Bonggoy Cruz | last post by:
I was able to convert our web application using the web project option (still have a lot of problem when converting to a vs2005 web site). It run without a problem on my machine. I deployed to our test environment and I got the following errors: Parser Error Message: Could not load file or assembly 'CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304' or one of its dependencies. The system cannot...
2
3387
by: Jeff | last post by:
Hey asp.net 2.0 My asp.net 2.0 project has got a assembly load problem: Some of my web.config settings: <membership defaultProvider="AH_MembershipProvider" userIsOnlineTimeWindow="15">
5
2713
by: =?Utf-8?B?VGhlIE1hbiBGcm9tIFNRTA==?= | last post by:
I'm having the darndest XML config file problem that I really need help with. I'm supporting a .NET 1.1 desktop application with its own config file, and I implement IConfigurationSectionHandler so I can have a custom config section in my config file. The IConfigurationSectionHandler.Create method just returns the 'section' XmlNode back to the consumer. The config file looks kind of like this: <?xml version="1.0" encoding="utf-8" ?>...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9376
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9326
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.