ProjectA includes EF code, and is normally hosted in MVC project. Now I'd like to "wrap" it in a Azure (v1) function (lets call ProjF), in order to expose on a consumptionplan (so we can scale the heavy calls).
So I ref ProjA, fine. But how to get all the EF settings over? Connectionstring goes via fina via host.settings.json, but the remaining from web.config ?
(notice we use PostgresSql and Devart). Since the azure function has no app.config or web.config, these settings has to be set elsewhere.
Relevant sections from web.config:
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
and
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Devart.Data.PostgreSql" type="Devart.Data.PostgreSql.Entity.PgSqlEntityProviderServices, Devart.Data.PostgreSql.Entity.EF6, Version=7.12.1328.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Devart.Data.PostgreSql" />
<add name="dotConnect for PostgreSQL" invariant="Devart.Data.PostgreSql" description="Devart dotConnect for PostgreSQL" type="Devart.Data.PostgreSql.PgSqlProviderFactory, Devart.Data.PostgreSql, Version=7.12.1328.0, Culture=neutral, PublicKeyToken=09af7300eec23701" />
</DbProviderFactories>
</system.data>
Have looked at the solution from
How to specify EntityFramework ProviderName in an Azure Function
but cannot figure out what values to use since we're using Postgres + Devart
When app.config is not available, you can add register DbProviderFactory and EF6 provider via code. An example is here: https://forums.devart.com/viewtopic.php?t=28550#p97525.
Related
I'm setting up a solution containing two projects: 1) my class library and 2) my web UI. Ultimately the website will be used to show query results from an existing mysql database.
I struggled to create the ado.net entity model for a while. But I thought I had figured it out after updating the mysql connector for visual studio and following the instructions here: https://dev.mysql.com/doc/connector-net/en/connector-net-entityframework60.html
Now that the entity model is created I am struggling to create a simple controller with scaffolding. I've double checked my connection string and ef provider in web.config and app.config.
I've looked through these questions but have not found my answer:
Exception has been thrown by the target of an invocation- while creating the controller
Application can't scaffold items
Enity Framework With MySQL
I'm pretty sure the issue is in how I have configured it. For a while I thought that what is in app.config didn't matter because the UI project (containing web.config) was set as the startup project. Now I'm just confused. Which is why I have included both below. Any insight is greatly appreciated.
From web.config:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-MySolution.UI-20161111094519.mdf;Initial Catalog=aspnet-MySolution.UI-20161111094519;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="MySolutionEntities" connectionString="metadata=res://*/Entities.DevData.csdl|res://*/Entities.DevData.ssdl|res://*/Entities.DevData.msl;provider=MySql.Data.MySqlClient;provider connection string="server=****;user id=****;password=****;database=mydatabase""
providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
<provider invariantName="System.Data.MySqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFrameworkSqlServer" />
</providers>
</entityFramework>
From app.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
<provider invariantName="MySql.Data.SqlClient"
type="MySql.Data.Entity.SqlServer.ProviderServices, EntityFramework.SqlServer"/></providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="MySolutionEntities" connectionString="metadata=res://*/Entities.DevData.csdl|res://*/Entities.DevData.ssdl|res://*/Entities.DevData.msl;provider=MySql.Data.MySqlClient;provider connection string="server=****;user id=****;password=****;database=mydatabase""
providerName="System.Data.MySqlClient" />
</connectionStrings>
</configuration>
Late answer but I hope it helps somebody
I had same problem, I just solve it by uninstalling and reinstalling entity-framework through the nuget package manager console.
o Run Package Manager Console :
Tools -> NuGet Package Manager -> Package Manager Console
To Remove:
UnInstall-Package EntityFramework
To Reinstall:
Install-Package EntityFramework
I hope this works for you as well
Ok I'm not exactly sure how I solved this problem but I figured that I should try to describe it. I started over my solution in the same way and created the entity model. Then instead of using the code in the providers tag from that article at dev.mysql.com (link above) I found this in my app.config:
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
I copied the same thing over to my web.config. Then I was able to create the controller with scaffolding.
After 8 hours of struggle debugging EFPowerTools, I found at C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\PrivateAssemblies was Mysq.Data and Mysql.Data.Ef6 which were a diffrent version [6.9.8] from the ones in my web config [6.10.9] i copied the versions in my bin 6.10.9 to the above PrivateAssemblies folder and every thing worked fine.
I'm trying to use Entity Framework to update-database.
It's running fine with no errors. When I use -Verbose it's showing
Target database is: 'PokemonAppCore.PkmnContext' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention)
But in the app.config I've pointed it to a local db, like so. Nothing is showing up in SQL Server Explorer under LocalDb.
Why is it using .\SQLEXPRESS instead of localdb like it's specified in app.config?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<connectionStrings>
<add name="PkmnConnectionString"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=PkmnDatabase;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
At first and as mentionned by Mohammad Akbari, it's important to pass your connectionstring name on DbContext constructor.
I'd like to add one more thing, the startup project (in VS solution) should be the one where EF is used, the update-database command is seeking for web.config (or app.config) of startup project.
Regards,
On my development system (VS2013 , MySql connector net 6.8.3 installed) my program works as expected. I'm using the NuGet packages EntityFramework.6.1.0, MySql.ConnectorNET.Data.6.8.3.2 and MySql.ConnectorNET.Entity.6.8.3.2
On production I need to use the Entity Framework with MySql (e.g. 6.8.3) without installing it.
On my test system MySql connector net 6.2.3 is installed, the program should run with the MySql connector Net 6.8.3. The needed dll's (6.8.3 and EF6) are in the same directory as my c#-exe. I get the following error:
System.DllNotFoundException: MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d
The problem was already described in https://stackoverflow.com/q/23465559/3604523 but the solution to install mysql and pick it up from GAC is not a solution for me, because we need to deploy a mysql.data.dll independent from potentially installed mysql data providers.
(How) is this possible?
Here is my app.config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DbContext" connectionString="metadata=res://*/Test.csdl|res://*/Test.ssdl|res://*/Test.msl;provider=MySql.Data.MySqlClient;provider connection string="server=mytestserver;port=3306;User Id=root;password=;Persist Security Info=True;database=mytestdb"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<system.data>
<DbProviderFactories>
<clear />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</providers>
</entityFramework>
</configuration>
I'm trying to use Entity Framework with SQLite. I had issues integrating it into my main application, so I started a little test from scratch, exactly following the directions on http://brice-lambson.blogspot.com/2012/10/entity-framework-on-sqlite.html
After all is said and done, I get the following error when running the project:
No Entity Framework provider found for the ADO.NET provider with
invariant name 'System.Data.SQLite'. 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.
My app.config looks like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="SQLite Data Provider"
invariant="System.Data.SQLite"
description="Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="ChinookContext"
connectionString=
"Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite"
providerName="System.Data.SQLite" />
</connectionStrings>
</configuration>
Then I saw his post about Entity Framework 6. While it wasn't the exact error I was getting, I tried installing his updated provider via NuGet. The error was gone, but replaced with this one:
Could not load file or assembly 'System.Data.SQLite.Linq,
Version=2.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or
one of its dependencies. The located assembly's manifest definition
does not match the assembly reference. (Exception from HRESULT:
0x80131040)
Additionally, my app.config got changed (slightly) to this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq, Version=2.0.88.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description="Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
<remove invariant="System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="ChinookContext" connectionString="Data Source=|DataDirectory|Chinook_Sqlite_AutoIncrementPKs.sqlite" providerName="System.Data.SQLite" />
</connectionStrings>
</configuration>
I've tried everything I can think of to address these errors, nothing has worked. I've tried using the other SQLite binaries; I've tried manually editing the SQLite project to use the EF version 6; I've changed the architectures, I've added and removed the nuget packages over and over, etc.
I have no idea where to go from here.
Just thought I'd share another way to configure EF6 with SQLite without using app.config / web.config. EF6 now supports code based configurations as outlined here on msdn. I used the following code (updated to remove reflection thanks to Sly):
public class SQLiteConfiguration : DbConfiguration
{
public SQLiteConfiguration()
{
SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance);
SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance);
SetProviderServices("System.Data.SQLite", (DbProviderServices)SQLiteProviderFactory.Instance.GetService(typeof(DbProviderServices)));
}
}
I use this so I can inject the correct DbContext and hence DbProvider at runtime and don't need everything configured in the main assembly.
Edit:
As Reyn said you will also need to add an IDbConnectionFactory for SQLite if you wish to have your connection string in your web.config / app.config file. Another approach is to call a different base constructor from your DbContext which passes in a new SQLiteConnection rather than the connection string, as shown in this answer.
I know this is an old question, but no one seems to have provided an answer that actually uses the .config file. Here is the system.data and entityframework sections of my web.config that allows connections to both SQLServer and Sqlite databases:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)"
invariant="System.Data.SQLite.EF6"
description=".NET Framework Data Provider for SQLite (Entity Framework 6)"
type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite.EF6"
type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite"
type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
Based on magicandre1981's comment, I began to look more closely at the syntax of the provider node. I found that my assembly was a different version than what was specified in the type attribute, though I had not inserted or touched that particular line. By deleting the strong naming, I got .Net to load the library. For reference, here's the new line:
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.SQLiteProviderServices, System.Data.SQLite.Linq" />
That put me back on track and I was able to match my results with the ones on the blog.
I feel compelled to note, however, that I have decided that SQLite is not a good fit for the Entity Framework, as too many critical functions are missing. I switched over to SQL Server Compact Edition, which I installed via NuGet. A simple tweak to my Connection String and I was running with the full power of Entity Framework. It took less than a minute, compared to the multi-hour slog that was SQLite. I'd recommend switching databases if possible, System.Data.SQLite just isn't ready for the Entity Framework.
For anyone using the code based setup and still getting the same exception: I needed to additionally set the connection factory in kjbartel's answer.
public class SQLiteConnectionFactory : IDbConnectionFactory
{
public DbConnection CreateConnection(string nameOrConnectionString)
{
return new SQLiteConnection(nameOrConnectionString);
}
}
Then set the default connection factory in SQLiteConfiguration
public class SQLiteConfiguration : DbConfiguration
{
public SQLiteConfiguration()
{
SetDefaultConnectionFactory(new SQLiteConnectionFactory());
SetProviderFactory("System.Data.SQLite", SQLiteFactory.Instance);
SetProviderFactory("System.Data.SQLite.EF6", SQLiteProviderFactory.Instance);
Type t = Type.GetType( "System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6");
FieldInfo fi = t.GetField("Instance", BindingFlags.NonPublic | BindingFlags.Static);
SetProviderServices("System.Data.SQLite", (DbProviderServices)fi.GetValue(null));
}
}
I have a similar problem as the one presented in the question
No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient', the error has the following message:
"The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details."
As the answers to the related question suggest, I have reinstalled Entity Framework (EF6) via the Package Manager Console, but the error persists. I also checked that EntityFramework.SqlServer.dll is referenced in my project.
Here is the connection string as stored in App.config:
<add name="DesignModel" ConnectionString="metadata=res://*/DesignModel.csdl|res://*/DesignModel.ssdl|res://*/DesignModel.msl;provider=System.Data.SqlClient;provider connection string="data source=C071E;initial catalog=CTD2;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
I have another project where I used EntityFramework to create the exact same entities and context, and it works fine, which makes this all more puzzling.
The error is shown when trying to execute this lines:
DesignModel designContext = new DesignModel();
designContext.MoPerfIDs.Load();
where DesignModel is the name of the class that inherits DbContext.
Here's the full App.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section name="ppe.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DesignModel" connectionString="metadata=res://*/DesignModel.csdl|res://*/DesignModel.ssdl|res://*/Design Model.msl;provider=System.Data.SqlClient;provider connection string="data source=MONNMC071E;initial catalog=CTD2;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlClient" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
Any help will be appreciated. Thanks in advance.
You need to register the Entity Framework provider for the System.Data.SqlClient SQL connection type.
you should have in app.config:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
Still not sure what was causing the problem, but ended up creating a new solution and copying everything from my project. Now works fine. Really weird, indeed.
Simply install "MySql.Data.Entity" from nuget! It will install mysql ado driver and entity driver automatically!
Wow...that is pretty special...Anyways. You need to register the Entity Framework provider for the System.Data.SqlClient SQL connection type.
You want to add the following to your app.config/web.config
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
<parameters>
<parameter value="System.Data.SqlClient" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
There are 2 options which you can try.
1) Load "System.Data.SqlClient" manually
Include the follow statement in your context class
var type = typeof(System.Data.Entity.SqlServer.SqlProviderServices);
2) Don't load "System.Data.SqlClient"
By change from
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
to
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
I hope your issue is resolved.
Try adding
var _ = System.Data.Entity.SqlServer.SqlProviderServices.Instance;
in the ctor of your designContext.
The problem in my case was that inorder to catch another exception I had enabled CLR exceptions. And I forgot to disable it.
I disabled it in my exception setting. and it overlooked this exception and went on to run and create a db for me (in my case) automatically.
I got this error but for me it was something entirely different.
I had to edit:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
And:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config
Searching for DbProviderFactories both configs looked like this:
<system.data>
<DbProviderFactories>
<add name="IBM DB2 for i .NET Provider" invariant="IBM.Data.DB2.iSeries" description=".NET Framework Data Provider for IBM i" type="IBM.Data.DB2.iSeries.iDB2Factory, IBM.Data.DB2.iSeries, Version=12.0.0.0, Culture=neutral, PublicKeyToken=9cdb2ebfb1f93a26" />
</DbProviderFactories>
<DbProviderFactories />
</system.data>
When I removed the trailing <DbProviderFactories /> everything started working again.
I was able to solve it by looking at only Unable to find the requested .Net Framework Data Provider and finding this answer:
https://stackoverflow.com/a/9929534/3850405
If you get this error on Visual Studio while debugging, this happens after you installed another DB provider or IDE with DB Provider. I faced this error after I installed Delphi on my computer.
Solution: Just edit C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config and remove tags.