Introduction
Two weeks ago, I posted a first version of a library which was able to synchronize data between a generated dataset (by CSC) and a database. To do this job, the only requirement for the tool is a DataSet with DataAdapters.
But after using this library, I realized two real problems in the production environment.
First, if there were some errors during the saving process, I didn't know where the problem was. I have fixed this problem using the well known "Log4Net" assembly. Here are two sources which helped me to use it:
Secondly, the transaction was not implemented. Then if an error had occurred, some data was saved... other data was not. In order to do this job efficiently, I propose this good solution:
Using the Code
In order to use the TransacDatasetAdapter
, you will have to:
- Add a reference to the assembly
DataDigest.Datas
in your project - Add the configuration requirements if you need the log features. In my sample project, I propose a configuration which will save your logs in a flat text file. You could find more information in the URI proposed in the introduction.
All is done... may be you need to know how to use this library now.
If you have read the previous article about DataSetAdaptor
(I had called it Adaptor
... now I know it has to be named DataSetAdapter
), you won't be lost. In fact in this project, I have made some refactoring in the first version and then I have extended the DataSetAdapter
base with TransacDataSetAdapter
. Using it is the same philosophy, the only difference is the naming convention, and a connection property which needs to be set (using the adapter associated with the datatable that you give in the parameter).
Now, let's move on to what you are certainly more interested in.
Init the adaptor:
TransacDatasetAdapter<SAMPLEDBDATASET> dtsAdaptor
= new TransacDatasetAdapter<SAMPLEDBDATASET>(dataSet);
Set the connection property (this connection will be used for the transaction). As you can see, it is a datatable which has been sent. By reflection, the assembly will find its tableadaptor and get its connection property.
dtsAdaptor.SetConnection(dataSet.Car);
Loading process, same idea as in the past...
To download data from database to dataset, you will specify it to the adaptor like that:
dtsAdaptor.Fill();
Saving process, same idea as in the past...
dtsAdaptor.SaveChanges();
The Design of the Application
Conclusion
Not a lot of work was needed to make this code really more robust... may be not the best yet... But not too far I hope. Thank you for your feedback in order to improve (or not) this tool.
Little Tip
I wanted to refresh the content of my log file during my tests... I remembered an existing tool on the Linux environment... therefore I had a look at "tail" for Windows... I found it here.
May be there are other tools to do it, but this one was clearly enough for me.
History
- 7th November, 2006
- Idea of
DataSetAdaptor
from here
- 22nd November, 2006
- A first try at implementing error handler
- 29th November, 2006
DataSetAdaptor
renamed to DataSetAdapter
(stupid but logical)DataSetAdapter
extended by TransacDataSetAdapter
Log4Net
implemented
* Bachelor of Information Management at ISAT Charleroi in Belgium.
* Master II of Information science at UMH Mons.
I spend my time in small projects which can help me or small enterprises and
I am very interested in designing projects
with specifications of UML or in applying usual design patterns.