Unable to determine the provider name for provider factory of type "System.Data.Sqlite.SqliteFactory" Unable to determine the provider name for provider factory of type "System.Data.Sqlite.SqliteFactory" sqlite sqlite

Unable to determine the provider name for provider factory of type "System.Data.Sqlite.SqliteFactory"


I got the answer by myself, but I still don't know the root cause, now it works. I changed webconfig, here is the webconfig that make my project to work.

I added a provider that is "System.Data.Sqlite", Please note its type that is same with System.Data.Sqlite.EF6

  <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

  <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />  <remove invariant="System.Data.SQLite.EF6" />

Here is all configure.

 <entityFramework>    <providers>      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />    </providers>  </entityFramework>  <system.data>    <DbProviderFactories>      <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" />      <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" />    </DbProviderFactories>  </system.data>


That was a super-great answer zhnglicho!

Another option, aside from placing the providers and DbProviderFactories into the app.config or web.config, is to code your ProviderFactories and use it in your implementation of DbContext.

Usings:

using System.Data.Entity;using System.Data.Entity.Core.Common;using System.Data.Entity.ModelConfiguration.Conventions;using System.Data.SQLite;using System.Data.SQLite.EF6;

Config Class:

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)));    }}

Place this in your constructor:

public PythonContext() : base($"name=pythonSource"){    DbConfiguration.SetConfiguration(new SQLiteConfiguration());}

I've run unit tests against both methods (this one and the zhnglicho answer) and i've not found any speed differences.

Debug Output (getting a record count and a random quote from the sqlitedb):

Found 18307 RecordsPresenter: 'And Miles Yellowbird, up high in banana tree, the golfer and inventor of Catholicism.'Debug Trace:Native library pre-loader is trying to load native SQLite library "C:\Users\***\***\\SQLiteTests\bin\Debug\x64\SQLite.Interop.dll"...

I up-voted the previous answer as it worked for me, but this is just a suggestion if you don't want to jack with your configs. ~ PEACE!