views:

146

answers:

5

I need to store a list of columns/datatype pairs as app settings. The amount of column/datatype pairs will be around 50 - 100, but could be more. I cannot store these in a table due to client requirements. There will be UI for the user to add/edit/delete from the list.

I was initially thinking of a delimited string stored in app.config. Is there a practical limit to the size of string stored in a key in app.config?

Is there a better way?

[edit following sanjii's comment] is it possible to read/write an xml file with a dataset?

+1  A: 

Since these settings get loaded into memory when you application starts you are safe to store values in a config that would fit in memory. In other words it is exactly as if you had hardcoded the string in C# (as far as memory utilization is concerned).

As an alternative, would your client obligations preclude the use of something like SQLite?

SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine. SQLite is the most widely deployed SQL database engine in the world. The source code for SQLite is in the public domain.

Andrew Hare
+10  A: 

I would store them in a XML file. You could use XML Serialization or simply a DataSet.

DSUser ds = new DSUser();
ds.ReadXml(fileName);

ds.AcceptChanges();
ds.WriteXml(fileName);
Arthur
+1 It seems like a perfect scenario for XML, though I prefer plain XML serialization to the DataSet option.
santiiiii
I'm with @santiiiii (hopefully there's enough i's there) but I've done this for some quick and dirty serialization and it worked great.
Austin Salonen
Is it possible for a dataset to read write to an xml file?
callisto
@callisto: It's just as easy as @Arthur posted above, where "filename" is the path to said XML file!
Joey
I actually meant a typed dataset...
callisto
Yes - this was indeed a quick solution for a simple task. I just had to store up to 10 User. When it gets more complex I also prefer the XML Serialization method.
Arthur
+1  A: 
Yoopergeek
Note: It is possible to create custom appconfig sections that use more complex, hierarchical structures.
Brian
You're right. Unfortunately I've only briefly ever read about that and haven't had a chance to implement anything. Got any good links that I should keep around for future reading?
Yoopergeek
A: 

I also vote for XML based settings solution. You can find a nice example at DotNetBlogEngine Source Code.

It's based on a basic Xml File , a singleton Settings Class and a SettingsProvider for read&write related stuff. After proper implementation , all you have to do to reach settings is calling an instance of settings class ;

ApplicationSettings.Instance.Name = "MyApplicationName";
ApplicationSettings.Instance.Description = "It's an awesome application";
ApplicationSettings.Instance.Theme = "LoveThemeofMGS";
ApplicationSettings.Instance.Save();

testlabel.Text = ApplicationSettings.Instance.Name;
testlabel2.Text = ApplicationSettings.Instance.Description;

I personally use this for most of my Web Projects , it's an easy&clean solution.

Tiax
A: 

1) Like most of the people who answered your question - I think that using some kind of XML based configuration will be the most convenient. I think that appconfig should be enough. It depend on you if Properties.Settings.Default is all you need, or maybe you need to use ConfigurationManager just for some more sophisticated tasks.

2) If you want to use typed dataset you should use xsd.exe tool (available in both: Visual Studio Packaga, and .Net Framework SDK). This little tool allows you to generate schema from xml file, and code or typed dataset from schema. Really useful.

3) If you consider using in memory database... maybe it will be much better to use Microsoft's SQL Compact Server instead of SQLite? (be aware that there are some problems with dealing with date fields while using SQLite)

MaciekTalaska