473,405 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Can I store this in app.config?

I'd like to store something such as the following the my app.config
file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="DEBUG" value="true"/>
<add key="DEBUGCleanFile" value="true"/>
</appSettings>

<DataGridColumnCollection>
<AGrid value="true">
</AGrid>
<BGrid value="false">
<column1 value="true"/>
<column2 value="true"/>
<column3 value="true"/>
</Bgrid>
</DataGridColumnCollection>

<system.diagnostics>
</system.diagnostics>
</configuration>

I particularly want the DataGridColumnCollection section. I can read
the data fine out of the file using an XMLDocument object. However,
weird things happens. For example, on this line:

using(SqlConnection connection = new SqlConnection(connectionString))

I get this exception:

The type initializer for 'System.Data.SqlClient.SqlConnection' threw an
exception.

The app.config and above line are completely unrelated. When I remove
the DataGridColumnCollection, everything is fine but of course I loose
all of that data. For now, I'm using my own XML file but that is just
more files to haul around. Any suggestions on how I can stick the
DataGridColumnCollection section into app.config?

Thanks,
Brett

Aug 11 '06 #1
10 3641
Hello Brett,

DataGridColumnCollection is a class, as I understand?
Then serialize it and keep it encoded just like a string

BRI'd like to store something such as the following the my app.config
BRfile:
BR>
BR<?xml version="1.0" encoding="utf-8" ?>
BR<configuration>
BR<appSettings>
BR<add key="DEBUG" value="true"/>
BR<add key="DEBUGCleanFile" value="true"/>
BR</appSettings>
BR<DataGridColumnCollection>
BR<AGrid value="true">
BR</AGrid>
BR<BGrid value="false">
BR<column1 value="true"/>
BR<column2 value="true"/>
BR<column3 value="true"/>
BR</Bgrid>
BR</DataGridColumnCollection>
BR<system.diagnostics>
BR</system.diagnostics>
BR</configuration>
BRI particularly want the DataGridColumnCollection section. I can
BRread the data fine out of the file using an XMLDocument object.
BRHowever, weird things happens. For example, on this line:
BR>
BRusing(SqlConnection connection = new
BRSqlConnection(connectionString))
BR>
BRI get this exception:
BR>
BRThe type initializer for 'System.Data.SqlClient.SqlConnection' threw
BRan exception.
BR>
BRThe app.config and above line are completely unrelated. When I
BRremove the DataGridColumnCollection, everything is fine but of
BRcourse I loose all of that data. For now, I'm using my own XML file
BRbut that is just more files to haul around. Any suggestions on how
BRI can stick the DataGridColumnCollection section into app.config?
BR>
BRThanks,
BRBrett
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsche
Aug 11 '06 #2
I'm not using that class. Let's call it MyDataGridColumnCollection. I
still get the sqlclient exception.

Thanks,
Brett

Aug 11 '06 #3
Brett,
If you want to store custom XML elements/ nodes in a configuration file,
they must either be recognized elements, or simple key=x value=y elements in
the appSettings section.
Otherwise, you need to declare a custom configuration section in your
config and have a custom sectionhandler to read it. Michael's comments about
serializing a class are correct.
Obviously, some study will be required but if this is the way you want to
store your custom data, it will be worth it.
Peter

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


"Brett Romero" wrote:
I'd like to store something such as the following the my app.config
file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="DEBUG" value="true"/>
<add key="DEBUGCleanFile" value="true"/>
</appSettings>

<DataGridColumnCollection>
<AGrid value="true">
</AGrid>
<BGrid value="false">
<column1 value="true"/>
<column2 value="true"/>
<column3 value="true"/>
</Bgrid>
</DataGridColumnCollection>

<system.diagnostics>
</system.diagnostics>
</configuration>

I particularly want the DataGridColumnCollection section. I can read
the data fine out of the file using an XMLDocument object. However,
weird things happens. For example, on this line:

using(SqlConnection connection = new SqlConnection(connectionString))

I get this exception:

The type initializer for 'System.Data.SqlClient.SqlConnection' threw an
exception.

The app.config and above line are completely unrelated. When I remove
the DataGridColumnCollection, everything is fine but of course I loose
all of that data. For now, I'm using my own XML file but that is just
more files to haul around. Any suggestions on how I can stick the
DataGridColumnCollection section into app.config?

Thanks,
Brett

Aug 12 '06 #4
Brett Romero писал(а):
I'd like to store something such as the following the my app.config
file:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="DEBUG" value="true"/>
<add key="DEBUGCleanFile" value="true"/>
</appSettings>

<DataGridColumnCollection>
<AGrid value="true">
</AGrid>
<BGrid value="false">
<column1 value="true"/>
<column2 value="true"/>
<column3 value="true"/>
</Bgrid>
</DataGridColumnCollection>

<system.diagnostics>
</system.diagnostics>
</configuration>
...
You better look for the solution at the addrress

http://www.codeproject.com/csharp/readwritexmlini.asp

I use it for the near purposes and it works. May be you only would be
forced to change
from the appearance <column1 value="true"/to a <add key="column1"
value="true"/for all the entry in your custor section.
But in your program read results would be the same as you a need, I
suppose. In the same time this solution allows you to store the same
info in INI, XML and Registry in the same manner.

Aug 12 '06 #5
Thanks Sygsky. The sections I create during one app session may not
be there in the next app session. For example, below AGrid has a
value of true. If it were false, it would have column element entries,
as does BGrid. The value and additional entries depend on if the user
has selected to show those particular columns.

<DataGridColumnCollection>
<AGrid value="true">
</AGrid>
<BGrid value="false">
<column1 value="true"/>
<column2 value="true"/>
<column3 value="true"/>
</Bgrid>
</DataGridColumnCollection>

The point is that the above will always be changing with respect to the
number of column elements under each xGrid parent and of course values
will change. There will always be an xGrid entry but the number
columns below it will vary. Right now, I'm using my own XML file and
everything works fine but I don't like dragging this additional file
around. If I use app.config, will it take a great amount of effort to
do the same thing I'm doing now (constantly removing/adding elements)?
I know using app.config just to change "value"s works is simple.

Thanks,
Brett

Aug 12 '06 #6
In .Net 2.0 you can use the new settings architecture that supports
typed values.

I've used the type System.Xml.XmlDocument with no problems.

Tigger

Aug 13 '06 #7
Tigger wrote:
In .Net 2.0 you can use the new settings architecture that supports
typed values.

I've used the type System.Xml.XmlDocument with no problems.

Tigger
Are you saying it can be used with app.config or with a custom XML
file? Can you give an example?

Thanks,
Brett

Aug 13 '06 #8

Brett Romero wrote:
Tigger wrote:
In .Net 2.0 you can use the new settings architecture that supports
typed values.

I've used the type System.Xml.XmlDocument with no problems.

Tigger

Are you saying it can be used with app.config or with a custom XML
file? Can you give an example?

Thanks,
Brett
Its used with app.config but its a new schema for .Net 2.0 settings.

The easiest way is to use Studio 2005 and edit your settings via the
projects properties. This creates a wrapper class for your settings
which you can use to access the settings. e.g.

If you create a setting called MyXmlDocument of type System.XmlDocument
you can access it via...

Properties.Settings.Default.MyXmlDocument

Settings are stored in the app.config in configuration sections. If you
do the above your app.config file should be updated to include the
MyXmlDocument setting... something like
....
<setting name="MyXmlDocument" serializeAs="Xml">
<value>
<MyDocumentElement>Hello World</MyDocumentElement>
</value>
</setting>
....
This will be within a set of nodes which depend on your project and if
the variable is application or user level. The <configSectionsat the
top defines this.

Tigger

Aug 14 '06 #9
The thing I'm storing to file is a dictionary<string, dictionary<,>>
type. Parent nodes are in the first dictionary and child nodes in the
second. I'm only serializing values depending on the value in the
child dictionary. I can see this turning into something that will
takes days to get going with the app.config file.

Doesn't app.config want to serialize the entire class, say
MyXMLDocument? I don't want it all serialized. Just the particular
dictionary.

Thanks,
Brett

Aug 14 '06 #10
How you take your objects and convert them to/from xml is up to you.

Note: I think you can use any xml serialisable object as a config
variable, but I believe generic collections are not xml serialisable.
So no matter what, you would have to create your own serialiser.

Tigger
Brett Romero wrote:
The thing I'm storing to file is a dictionary<string, dictionary<,>>
type. Parent nodes are in the first dictionary and child nodes in the
second. I'm only serializing values depending on the value in the
child dictionary. I can see this turning into something that will
takes days to get going with the app.config file.

Doesn't app.config want to serialize the entire class, say
MyXMLDocument? I don't want it all serialized. Just the particular
dictionary.

Thanks,
Brett
Aug 14 '06 #11

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

Similar topics

16
by: DraguVaso | last post by:
Hi, I have a Windows Service running (made in VB.NET), and wanted to be able to change from time to time some parameters by changing them in the App.config. But it seems that the application...
2
by: Chris Dunaway | last post by:
I have a web service that references a data class library which performs SQL Server access. Since the web service is also a class library, there is no App.Config, only Web.config. Is Web.Config...
5
by: Guadala Harry | last post by:
What are my options for *securely* storing/retrieving the ID and password used by an ASP.NET application for accessing a SQL Server (using SQL Server authentication)? Please note that this ID and...
2
by: John Wildes | last post by:
hello I was wondering if someone could point me in the direction of information on using app.config to store string variables. I have a couple of variables that store path information for file...
10
by: Mike9900 | last post by:
Hello, I would like to store application expiration date in a file and store that file in a secure place, so the application can access the file for all the users on that computer. ...
8
by: aabdis | last post by:
Hello All.... I have a question... i have two Windows apps (one UI, and one service) which use a common DLL that hands out database results and such to the two apps. The DLL always connects to...
21
by: Nick Craig-Wood | last post by:
Lance Gamet <lance@gamet.comwrote: I've found http://docs.python.org/lib/module-ConfigParser.html To be easy to use and built in. It makes human readable / editable ..ini - like files. ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectplanning, coding, testing,...
0
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...

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.