Thursday, November 12, 2009

Implementing a .NET Framework Data Provider

Five years ago I needed to implement a web app for a chemicals company, that was using data from SqlServer, Oracle, Documentum and Hummingbird. The problem was that at that time both Documentum and Hummingbird (document management systems) had no oledb nor .net providers available. So my data layer became a big mess due to the fact that some of my code was through ADO.NET and the rest was using proprietary API's from Documentum and Hummingbird. In addition having such code was very error prone and not testable at all, since those API's at that time were very low level.
The solution that I had found was to implement my own .NET Data Provider. I used as basis an example posted on msdn: Implementing a .NET Framework Data Provider.
The article provides a template implementation of a "Fake/Sample" data provider for an in-memory database "Fake/Sample". If you are investigating in this direction then following the above link will be very helpful.
For your convenience I have created a sample wpf app using this code. The code is an identical copy of the original; I have only made some improvements to make it up-to-date with .NET 4.0 since the initial article was written for .NET 1.0
You can checkout the sources using tortoise: http://bakopanos.googlecode.com/svn/trunk/blog/DotNetDataProviderTemplate/
I used Visual Studio 2010 for this :-)


An overview of the code

The "fake/sample" database in the sample mimics a real world database that returns a cursor of the following structure:

The commands supported by the sample database are startwith "select " and startwith "update ". This is it: 2 hardcoded commands, no args or anything...
  • The select command returns always the following resultset hardcoded in code:


  • The update command simply alters the (2,2) cell of the above table.
Once you understand this sample you can implement your own wrapper for the database of your choice. I am about to implement a dataprovider for reading a large number of xml files...

0 comments:

Post a Comment

Post a comment