ErikEJ / EntityFramework6PowerTools

This is the codebase for Entity Framework 6 Power Tools Community Edition, and modern EF 6 providers for SQL Server and SQL Server Compact
Other
183 stars 27 forks source link

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

Closed ShahidRasheed closed 2 years ago

ShahidRasheed commented 2 years ago

Hi Erik, I am updating our NuGet libraries to use Microsoft.Data.SqlClient. Libraries use .Net framework 4.7.2, and I have installed Microsoft.Data.SqlClient, along with your package.

I am running into the following exception: System.InvalidOperationException: The requested .Net Framework Data Provider's implementation does not have an Instance field of a System.Data.Common.DbProviderFactory derived type.

I have updated the config sections as per your suggestions:

<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />

`

`

`

</system.data>`

My connection string has also been updated, and I am using Active Directory Managed Identity authentication; the following is a sample connection string. <add name="ConStName" connectionString="Data Source={AzureManagedInstance};Initial Catalog={MyDB};Persist Security Info=True;Authentication=Active Directory Managed Identity;MultipleActiveResultSets=True" providerName="Microsoft.Data.SqlClient" />

Please let me know if you need any other details.

ErikEJ commented 2 years ago

A small console app that demonstrates the issue - maybe you need Code based configuration as well (dispite the docs saying something else) - I have not done a lot of .NET Framwork testing.

ShahidRasheed commented 2 years ago

@ErikEJ, what should be my defaultConnectionFactory? I have the following in my app config. <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />

ErikEJ commented 2 years ago

That looks wrong. I dont think my readme mentions that you should have that in your app.config.

But I cannot help you based on fragments of code, please share a runnable simple app that exhibits the issue.

ErikEJ commented 2 years ago

This sample should demonstrate app.config based use with .NET Framework

https://github.com/ErikEJ/EntityFramework6PowerTools/tree/community/test%2FSmokeTestNetFx

ShahidRasheed commented 2 years ago

Thanks, @ErikEJ. I had to register the provider in the code, and I see the app is now connecting. Please consider this issue closed. Note: I also had to remove the defaultConnectionFactory from the config.
image

ErikEJ commented 2 years ago

@ShahidRasheed There was missing parts in the app.config configuration, you need to add this as well, then pure app.config based configuration will work:

<system.data>
    <DbProviderFactories>
    <add name="SqlClient Data Provider"
        invariant="Microsoft.Data.SqlClient"
        description=".NET Framework Data Provider for SqlServer"
        type="Microsoft.Data.SqlClient.SqlClientFactory, Microsoft.Data.SqlClient" />
   </DbProviderFactories>
</system.data>
ShahidRasheed commented 2 years ago

@ErikEJ thanks, on comparison I see the type is different in my config. I will update the config and remove the code updates. Will send an update once done.

ErikEJ commented 2 years ago

@ShahidRasheed all required config is documented in the readme.