Custom Data Provider (continued) 5

As I mentioned in my last post, I’ve been creating a custom data provider using the new Data Provider Model in .NET Framework 2.0.

Everything went really smoothly until I wanted to use the DbProviderFactories.GetFactory() method to instantiate my class. I had registered my DbProviderFactory-derived class in machine.config and it was overriding all the abstract methods. According to every guide I could find (like this and this) that would be enough to be up and running with my new provider. But nooo, it just couldn’t be as easy as that, now could it? Every time I tried to create my provider I got the following message:

The requested .Net Framework Data Provider’s implementation does not have an Instance field of a System.Data.Common.DbProviderFactory derived type.

I tried googling, I tried looking through newsgroups but came up with no solution and no description of any steps I’d missed on the way. Finally, I decided to run ildasm on System.Data to find out what Microsoft did to the System.Data.SqlClient factory. And look what I found:

.field public static initonly class System.Data.SqlClient.SqlClientFactory Instance

It seems that all DbProviderFactory classes must be singletons, with the one and only instance being called “Instance”. Maybe they could have mentioned something about this in the documentation…

Well, the story doesn’t end here though. Because the next step is to try to get my new Data Provider to show up in the Data Source Configuration Wizard. It looks like there is something called the DDEX (Data Designer Extensibility) and I think that will be the place to look for more info…

5 thoughts on “Custom Data Provider (continued)

  1. Justin Jul 26,2006 15:59

    You really saved me a lot of time with that. Thanks.

    For those of us who aren't experts at reading IL, here's what your class has to look like in order for it to work properly:

    public class ProviderName : DbProviderFactory {
      public static ProviderName Instance = new ProviderName();

      …etc.
    }

  2. Anders Ljusberg Jul 26,2006 17:34

    Glad to have helped! Good luck with your provider!

  3. Derek Diamond Oct 24,2006 10:47

    Thanks a million. I got the first part right. Now how to get the provider details dialog to show with the least amount of pain……

  4. Vlad C May 19,2010 20:20

    Thank you very much for this information!!! You helped me a lot.

  5. Tomas Jun 5,2010 21:20

    Thanks so much!

Comments are closed.