1

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:

  • Project.UI: the front-end logic
  • Project.Model: the POCO classes
  • Project.DataAccess: the data access logic: entity framework project

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

2 Answers 2

1

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" />
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, but where can I find the PublicKeyToken for SQLite?
This tell you how to get it.
I tried it, but I'm still getting the same error, weird thing is the error is about "System.Data.SqlClient.SqlConnection" while I'm using SQLite...
try adding a <clear /> before <add name="SQLite Data Provider"
That doesn't do it neither :(
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.