locked
Custom Data Provider not functional in .Net Framework 4.0 RRS feed

  • Question

  • Hi,

    I have a custom provider factory that im using to connect to MS SQL server. I have configured my machine such that my provider factory is used in place of the default provider factory.

    <remove invariant="System.Data.SqlClient"/>

    <add name="My SqlClient Data Provider" invariant="System.Data.SqlClient" description=".A simple data provider for sqlserver" type ="Simple.SqlClientFactory, MySql.Client, Version=5.6.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />

     

    The above configuration worked fine till 3.5. The problem arised when I tried the same provider on .Net Framework 4.0, looks like using the invariant name of the

    default provider is nolonger allowed.

     

    Any thoughts?

     

    Thanks in Advance
    Wednesday, February 23, 2011 1:32 PM

Answers

  • Hi!

    I'm not sure why they have done this, but my guesses is that one of the reasons is to avoid situations like the one you are trying to do, overriding default functionality with custom one.

    The reason why you don't get any error is that your configuration is in fact correct but since System.Data.SqlClient is a reserved name your changes in the configuration doesn't override the autogenerated data in the framework. The code itself does in fact fail silently when it tries to read your configuration and you are using an invariantname that is used by .NET. The reason for this could be that a bogus app.config/machine.config shouldn't stop an application.

    So, in .NET4 you cannot do what you did in 3.5 and earlier due to this change. So you have to redesign your solution in .NET4 to use your own custom invariantname, which is the correct way to add a provider.

    You could try to call DbProviderFactories.GetFactoryClasses() described in the link earlier to get the list of providers .NET knows about for your application.

    Sorry, but that is the only answer I have.


    --Rune
    • Proposed as answer by Jackie-Sun Friday, February 25, 2011 9:12 AM
    • Marked as answer by Jackie-Sun Tuesday, March 1, 2011 4:52 AM
    Thursday, February 24, 2011 7:42 AM

All replies

  • The default providers isn't listed in the machine.config anymore, that's why it doesn't work. its somehow detected dynamically from the runtime.

    This link describes it:

    http://social.msdn.microsoft.com/Forums/en-ZA/adodotnetdataproviders/thread/d79129c4-ae05-4c45-8997-bd90f5765a3a

    Anyway I find it a bit dangerous override system default names like System.Data.SqlClient. Why do you do this? Wouldn't it be easier to define your own invariant property and use this in the provider part of the entity connectionstring?

     


    --Rune
    Wednesday, February 23, 2011 5:04 PM
  • Hi Rune,

     

    Thanks for your quick response. So there is no way we can use the default invariant name? but the link says they are not listed, it does not say that the default invariant name is not allowed for use with custom providers. I suspect this has something to do with the permissions to override the default provider factories. Interestingly the above configuration does not throw any error.

     

    Ravi

    Thursday, February 24, 2011 6:37 AM
  • Hi!

    I'm not sure why they have done this, but my guesses is that one of the reasons is to avoid situations like the one you are trying to do, overriding default functionality with custom one.

    The reason why you don't get any error is that your configuration is in fact correct but since System.Data.SqlClient is a reserved name your changes in the configuration doesn't override the autogenerated data in the framework. The code itself does in fact fail silently when it tries to read your configuration and you are using an invariantname that is used by .NET. The reason for this could be that a bogus app.config/machine.config shouldn't stop an application.

    So, in .NET4 you cannot do what you did in 3.5 and earlier due to this change. So you have to redesign your solution in .NET4 to use your own custom invariantname, which is the correct way to add a provider.

    You could try to call DbProviderFactories.GetFactoryClasses() described in the link earlier to get the list of providers .NET knows about for your application.

    Sorry, but that is the only answer I have.


    --Rune
    • Proposed as answer by Jackie-Sun Friday, February 25, 2011 9:12 AM
    • Marked as answer by Jackie-Sun Tuesday, March 1, 2011 4:52 AM
    Thursday, February 24, 2011 7:42 AM