Sander Declerck
Sander Declerck

Reputation: 2535

Entity Framework Sqlite database: NotSupportedException

I followed this tutorial to start a project that uses Entity Framework 5 with a SQLite db: http://brice-lambson.blogspot.be/2012/10/entity-framework-on-sqlite.html

However, in my application, I have multiple projects:

Now I'm getting the following exception:

System.NotSupportedException was unhandled HResult=-2146233067
Message=Unable to determine the provider name for connection of type 'System.Data.SqlClient.SqlConnection'. Source=EntityFramework

I set up everything as in the tutorial, I installed EF5 and System.Data.SQLite into all projects. This is my App.config from the main project:

<?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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <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>
    <connectionStrings>
      <add name="EasyInvoiceContext" connectionString="Data Source=|DataDirectory|EasyInvoice_v1.sqlite" providerName="System.Data.SQLite" />
    </connectionStrings>
  </system.data>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

Does anybody have an idea what I'm doing wrong?

More source code of my project can be found on github: https://github.com/SanderDeclerck/EasyInvoice

Upvotes: 1

Views: 4000

Answers (2)

Sander Declerck
Sander Declerck

Reputation: 2535

I found the solution, in the App.config connectionstrings should've been a child of configuration instead of being a child of system.data.

Here's the fixed App.config (tested, and working):

<?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=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <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="EasyInvoiceContext" connectionString="Data Source=|DataDirectory|Database/EasyInvoice_v1.sqlite" providerName="System.Data.SQLite" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
</configuration>

Upvotes: 0

Abhishek Punj
Abhishek Punj

Reputation: 289

Try using the full qualified assembly name while adding DBProviderFactory in the config.. something like this.

<add name="SQLite Data Provider" 
     invariant="System.Data.SQLite" 
     description=".Net Framework Data Provider for SQLite" 
     type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />

Upvotes: 1

Related Questions