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

No Entity Framework provider found for the ADO.NET provider with invariant name 'JetEntityFrameworkProvider' #53

Open
it19862 opened this issue Jul 20, 2020 · 3 comments

Comments

@it19862
Copy link

it19862 commented Jul 20, 2020

Error.
No Entity Framework provider found for the ADO.NET provider with invariant name 'JetEntityFrameworkProvider'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information. "

Question:
How do I resolve the error?

Used by

  • Windows - 7x64;
  • Microsoft Visual Studio Community 2019 - Version 16.6.3;

Description.
I am trying to connect to MS Access database - db_test_01.accdb.
I have created a console application.
I am using the instruction: https://www.youtube.com/watch?v=mI0un8jjqL8

I get an error: see the "Error" section above.

Picture
2020-07-20_21-04-13

Code
App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
    </startup>
	<connectionStrings>
		<add name="DefaultConnection"
			 connectionString="Provider=Microsoft.ACE.OleDB.12.0;Data source=c:\test\csharp\vs\db\db_test_01.accdb"
			 providerName="JetEntityFrameworkProvider"/>
	</connectionStrings>
</configuration>

Person.cs

using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;

namespace ConsoleApp
{
    class Person
    {
        public Person()
        {
            OwnerCars = new List<Car>();
        }

        public int Id { get; set; }
        
        [MaxLength(10)]
        public string Name{ get; set; }
        
        public virtual ICollection<Car> OwnerCars { get; set; }
    }    
    
}

Car.cs

using System.ComponentModel.DataAnnotations;

namespace ConsoleApp
{   
    class Car
    {        
        public int Id { get; set; }
     
        [MaxLength(10)]
        public string Name { get; set; }

        public virtual Person Owner { get; set; }
    }

}

Context.cs

using System.Data.Entity;

namespace ConsoleApp
{
    class Context : DbContext
    {

        public Context() : base("DefaultConnection")
        {

        }

        public DbSet<Car> Cars{ get; set; }
        public DbSet<Person> People { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            // base.OnModelCreating(modelBuilder);
            modelBuilder.Entity<Person>()
                .HasMany(_ => _.OwnerCars)
                .WithOptional(_ => _.Owner);
        }

    }
}

Program.cs

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            JetEntityFrameworkProvider.JetConnection.ShowSqlStatements = true;
            using (var context = new Context())
            {
                context.Cars.Count();
            }
            Console.ReadLine();
        }
    }
}
@bubibubi
Copy link
Owner

This is a section of an App.Config.
Could you check if your is similar?

</configuration>
  <entityFramework>
    <providers>
      <provider invariantName="JetEntityFrameworkProvider" type="JetEntityFrameworkProvider.JetProviderServices, JetEntityFrameworkProvider" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="JetEntityFrameworkProvider" />
      <add invariant="JetEntityFrameworkProvider" name="Jet Entity Framework Provider" description="Jet Entity Framework Provider" type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider" />
    </DbProviderFactories>
  </system.data>
</configuration>

@it19862
Copy link
Author

it19862 commented Jul 21, 2020

@bubibubi

This is a section of an App.Config.
Could you check if your is similar?

</configuration>
  <entityFramework>
    <providers>
      <provider invariantName="JetEntityFrameworkProvider" type="JetEntityFrameworkProvider.JetProviderServices, JetEntityFrameworkProvider" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="JetEntityFrameworkProvider" />
      <add invariant="JetEntityFrameworkProvider" name="Jet Entity Framework Provider" description="Jet Entity Framework Provider" type="JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider" />
    </DbProviderFactories>
  </system.data>
</configuration>

Question: How to connect these ("App.config" -bubibubi) + "App.config" (My)?

I do not understand you
My "App.config" (My).
<?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" /> </startup> <connectionStrings> <add name="DefaultConnection" connectionString="Provider=Microsoft.ACE.OleDB.12.0;Data source=c:\test\csharp\vs\db\db_test_01.accdb" providerName="JetEntityFrameworkProvider"/> </connectionStrings> </configuration>

You are providing "App.config" -bubibubi.

</configuration>
  <entityFramework>
    <providers>
      <provider invariantName = "JetEntityFrameworkProvider" type = "JetEntityFrameworkProvider.JetProviderServices, JetEntityFrameworkProvider" />
      <provider invariantName = "System.Data.SqlClient" type = "System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant = "JetEntityFrameworkProvider" />
      <add invariant = "JetEntityFrameworkProvider" name = "Jet Entity Framework Provider" description = "Jet Entity Framework Provider"
                type = "JetEntityFrameworkProvider.JetProviderFactory, JetEntityFrameworkProvider" />
    </DbProviderFactories>
  </system.data>
</configuration>

@it19862
Copy link
Author

it19862 commented Jul 26, 2020

@bubibubi
The topic is closed.
Thank.

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

No branches or pull requests

2 participants