Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 opened this issue Jul 26, 2022 · 8 comments
Labels

Comments

@ShahidRasheed
Copy link

ShahidRasheed commented Jul 26, 2022

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" />

<entityFramework> <providers> <provider invariantName="Microsoft.Data.SqlClient" type="System.Data.Entity.SqlServer.MicrosoftSqlProviderServices, ErikEJ.EntityFramework.SqlServer" /> </providers> </entityFramework>

<system.data> <DbProviderFactories> <add name="SqlClient Data Provider" invariant="Microsoft.Data.SqlClient" description=".Net Framework Data Provider for SqlServer" type="System.Data.Entity.SqlServer.MicrosoftSqlProviderServices, ErikEJ.EntityFramework.SqlServer" /> </DbProviderFactories> </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
Copy link
Owner

ErikEJ commented Jul 26, 2022

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
Copy link
Author

ShahidRasheed commented Jul 26, 2022

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

@ErikEJ
Copy link
Owner

ErikEJ commented Jul 26, 2022

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
Copy link
Owner

ErikEJ commented Jul 26, 2022

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

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

@ShahidRasheed
Copy link
Author

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 ErikEJ reopened this Jul 26, 2022
@ErikEJ ErikEJ closed this as not planned Won't fix, can't repro, duplicate, stale Jul 26, 2022
@ErikEJ ErikEJ reopened this Jul 27, 2022
@ErikEJ
Copy link
Owner

ErikEJ commented Jul 27, 2022

@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>

@ErikEJ ErikEJ closed this as completed Jul 27, 2022
@ErikEJ ErikEJ added the bug label Jul 27, 2022
@ShahidRasheed
Copy link
Author

@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
Copy link
Owner

ErikEJ commented Jul 28, 2022

@ShahidRasheed all required config is documented in the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants