Question DataSet to Xml...

JaedenRuiner

Well-known member
Joined
Aug 13, 2007
Messages
340
Programming Experience
10+
I've created a DataSet for use of storing application preferences, with the thought that I would preserve user settings in an xml file, and since the DataSet can import/export XML quite effectively I decided to use that. However, I'm getting a ConstraintException when I try to reload the export.

VB.NET:
Expand Collapse Copy
xw as XmlWriter
PreferencesDS.WriteXML(xw, IgnoreSchema)

VB.NET:
Expand Collapse Copy
PreferencesDS.ReadXML("default.xml", IgnoreSchema)

So i'm basically setting the data and exporting it to the file but on the read it says I'm violating some constraint issues. I have noticed that one of my fields is an expression field (not a persistent value) basing a computation off another Column's value. I'm wondering that since the column is Expression based, it is ReadOnly, and thus might be the cause of the constraint issue. That, as well as the ID fields for each of my tables are Auto Increment, which makes me wonder if they might be confused by the reading of the data from the xml file.

Is there a way to resolve this either by:
  • Determining the cause of the ConstraintViolation and ignoring it
  • Preventing certain Column/Fields from being written in the initial export (case and point the Expression column as it is not necessary to save.)

Thanks
 
Try including the schema when you write the xml file.

VB.NET:
Expand Collapse Copy
PreferencesDS.WriteXml("default.xml", XmlWriteMode.WriteSchema)

VB.NET:
Expand Collapse Copy
PreferencesDS.ReadXml("default.xml", XmlReadMode.ReadSchema)
 
Is there a way to resolve this either by:
  • Determining the cause of the ConstraintViolation and ignoring it
  • Preventing certain Column/Fields from being written in the initial export (case and point the Expression column as it is not necessary to save.)

Thanks

1) It's a relatively manual process I'm afraid. In the Immediate window, when you encounter your exception, type:

?myDs.MyTable.HasErrors
false

?myDs.MyOtherTable.HasErrors
true

(we now know the table with the error)
?myDs.MyOtherTable(0).RowError
""

?myDs.MyOtherTable(1).RowError
"The value for column 'abc' violates the MaxLength limit


you can maybe write some loops to do all this for you. I do have a DLL lying around somewhere that does this, scans every row of every datatable and reports any rowerrors found.. It's on the forums somewhere, called Nitpick


2) Double check in the XML file to see if they are there? I havent had a problem reading and writing expression fields before, and anything serialized to XML that has readonly properties, you find tha tthe serializer doesnt write the value, because it knows it cannot be deserialized again. e.g. if you made a class that had a RO and a RW property, only the RW property would be serialized by the default serializer. The RO property simply wouldnt appear in the file

Last point of note, .net2+ support a settings, (My.Settings) and offer binding to it directly - it may be easier for you to use this
 
Yes,

I did look into the My.Settings... However, it appears that I must manually create each individual setting, which for some things is alright, but I'm dealing with dynamic values that can change in the future.

Some are yea...well, Application Paths, and "Save Window Locations" etc, which the My.Settings would work perfectly for. But can I have the My.Settings Interpret and Parse a DataSet?

As well, My.Settings - isn't that user based? So If I log in as me, there will be one user.config, but if I log in as someone else, there will be a different one in their AppData folder? I sort of would prefer one settings file for the application, and store user specific configs internally...If that is possible to manipulate with the My.Settings please let me know...

Thanks
 
4th attmept at replying to this.. other 3 suffered random problems!

Yes,

I did look into the My.Settings... However, it appears that I must manually create each individual setting, which for some things is alright, but I'm dealing with dynamic values that can change in the future.

Well, application scope settings are made by the developer and dont change programmatically(but the xml file can be edited), user scope settings are editable prorgammatically

Remember that My.Settings is deserialized to an object and as such, cannot support variable number of prefs in a strongly typed fashion


Some are yea...well, Application Paths, and "Save Window Locations" etc, which the My.Settings would work perfectly for. But can I have the My.Settings Interpret and Parse a DataSet?
Er, you'd make MySettings remember the path to a dataset, then load and interpret it yourself.. Your question doesnt have enough detail to exapnd fully sorry.

As well, My.Settings - isn't that user based? So If I log in as me, there will be one user.config, but if I log in as someone else, there will be a different one in their AppData folder? I sort of would prefer one settings file for the application, and store user specific configs internally...If that is possible to manipulate with the My.Settings please let me know...
See above ref app scope vs user scope
 
I'll look into it for other things. But for now, consider this post answered.

I basically wanted a Global "Settings" file that retained all active users to this application as per the applications "users" not the "Computer" users, allowing for easier importing of settings from one user to another, no matter what system the Settings file was generated on, it can just loaded up and imported.

So in the end, I basically had an XmlWrapper class I made a while back, and utilized that to implement a down and dirty quick export/load/import/etc for my application that goes to the All Users\Application Data\MyCompany\MyApp folder location. The Default Settings are built into the app as a Resource File.

I will probably still need to look at that article though, so thanks, because I don't plan to use this settings file for personal settings - ie Form Sizes, locations, Fonts, Colors, etc. The settings I'm talking about are Column Mapping information from a Company Export File to my database, that sometimes may change and thus will need to be remapped by the user, however once it is remapped they can just send their settings file over to someone else and they can import the map too (or have the file on a network shared drive etc). Either way, it's not really the sort of thing that MySettings would be able to achieve easily, nor does it sound like what it is designed to be used for.

Thanks
 
If you use Application Scope settings, you the developer, will have control over them and can effect a change by editing the config xml (per machine)

If you use User Scope settings (and they can be mixed) then the settings the user chooses will follow him around a windows domain if he has a roaming profile

If your aim is to centrally control some app elements and guarantee user pref availability regardless of domain membership, use a database table
 
Back
Top