Best way to store configuration information in a database and be able to retrieve it using C#
-
Monday, May 07, 2012 7:57 PM
I have some configuration data I want to store in a database and retrieve via C#. Basically the information is going to dictate the form that will display (dictated by some dropdown lists). Basically this pairing of information will either ask for text values or perhaps yes/no dropdown depending on the pairs.
For example here are two pairings:
text-field,"What is the file name filename?" yes-no,"Is it printable?"
I actually got a proto working using XML (for the pairings). Not sure if that is the way to go. XML adds some extra work in constructing those pairings as I have to wrap them in node delimiters versus simple comma delimited pairings which I could potentially pick apart and split. Before I start down the XML path I thought I would reach out to the community to see if anyone else had any suggestions on the best way to go....
Petey100
All Replies
-
Monday, May 07, 2012 9:44 PM
How much data is involved? If it is only a few items then a db may be overkill. So you could use a simple csv or perhaps application settings.
If XML is overkill I suspect a db will be even more so. :)
Regards David R
---------------------------------------------------------------
The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones.
Object-oriented programming offers a sustainable way to write spaghetti code. - Paul Graham.
Every program eventually becomes rococo, and then rubble. - Alan Perlis
The only valid measurement of code quality: WTFs/minute.- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Wednesday, May 23, 2012 9:17 AM
-
Tuesday, May 08, 2012 5:01 AM
Hi,
application settings doesn't fit for your requirement? look into this
http://msdn.microsoft.com/en-us/library/bb397750.aspx
If you chosed db because of xml, why dont you serialize - deserialize object instead building xml your self? check from here how?
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx
still you are more towards saving into DB, probably you can have AppSettings table with
Id, key , type, value
and load on application start, so that through out application you can use. but, i would rethink about this approach.
I hope this helps you...
If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".
- Proposed As Answer by Matthew LIN Tuesday, May 08, 2012 6:55 AM
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Wednesday, May 23, 2012 9:17 AM
-
Tuesday, May 08, 2012 6:57 AM
Yes
you can use XmlSerializer to Serialize the config data object to Xml stream ,then save the xml stream to db.
and then load the xml stream to memory and deserialize xml to config data object.
DON'T TRY SO HARD,THE BEST THINGS COME WHEN YOU LEAST EXPECT THEM TO.
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Wednesday, May 23, 2012 9:17 AM
-
Tuesday, May 08, 2012 11:38 AM
Thanks for all the replies. The db is needed because the responses to the questions will be stored in the db so makes sense for portability (as this will be web based) to store the questions in the db. The number of questions are variable (depending on the 3 dropdowns that are selected). There could be one question or there could be 5. Also the questions could be text, number, a yes-no response or potentially other (future) types. I did proto some XML using XMLReader that read back nicely. This was the sample I used:
xmlString =
"<Config><Values><Text-Value>Printer Name</Text-Value><Yes-No-Value>Is One Page?</Yes-No-Value><Text-Value>Document Name</Text-Value></Values></Config>";
I could do the same thing, I guess with some other mechanism like:
Text-Value,Printer Name|Yes-No-Value,Is One Page?|Text-Value,Document Name
Does XMLSerializer gain me anything more than XMLReader if I go with the XML route?
Petey100
-
Friday, May 11, 2012 7:51 AMModerator
Hi Petey100,
How’s it going now? Do you have any updates about the previous issue?
Bob Shen [MSFT]
MSDN Community Support | Feedback to us
-
Friday, May 11, 2012 12:51 PM
Based on my research and feedback, I think XML route is best. I am planning to pull it out of a db field and pick it apart with XMLReader.Petey100
- Marked As Answer by Bob ShenMicrosoft Contingent Staff, Moderator Wednesday, May 23, 2012 9:17 AM

