3

I'm trying to understand how SQlite and entity frameworks interacts. I create a new fresh console project in my visual studio 2013. I install the nuget packet of SQlite 1.0.92. I create a new empty model (edmx) and try to populate it from a static example database (such as northwind.db). After this I get this error: error 0175: the ado.net provider named "System.Data.SQLite.EF6" is not registered on the computer.

Any ideas?

Thank you Lorenzo

LoxLox
  • 977
  • 9
  • 16
  • What version of Visual Studio are you using? How does your config file look like? – Pawel Mar 22 '14 at 02:39
  • VS2013. The config file is the one created after installing components with nuget – LoxLox Mar 22 '14 at 03:38
  • im getting "an Entity Framework database provider compatible with this version could not be found for your data connection", any ideas? for full description see http://social.msdn.microsoft.com/Forums/en-US/6a73f58f-4e71-453a-abf2-37e49e7db535/sqlite-vs2012-ef6-code-first?forum=Offtopic – Cel May 08 '14 at 13:18

2 Answers2

4

After some tests I found a possible solution. Let's start from the beginning:

Download the SQLite ado.net provider from sqlite server (x86 version). You have to manually register in the GAC those three libraries: system.data.sqlite, system.data.sqlite.ef6, system.data.sqlite.designer with gacutil

Start visual studio 2013. Add reference to nuget sqlite 1.0.92.0 (This will add reference to entity framework 6.1 too).

Your app.config will look like this:

<?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>
  <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>
  <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.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

    </providers>
  </entityFramework>
<connectionStrings>

Add a new Sqlite connection to the db in your server explorer and test it. Now add and create a new empty ado.net entity model to your project.

This should work... but when your run the application and pick up some records in one of the dbset you will get an exception telling you that there's no ado.net provider registered for your connection (system.data.sqlite).

Go to your config file and add this to you provider section (just copy the previous sqlite line and cut the .ef6 postfix in the invariant name):

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

Save all and rebuild the application. Now it works but if you go back to the model detail and try to refresh the model from the db you will get a provider exception again. Comment the last provider added and retry. IT WORKS!!!

I think it's due to a conflict between provider names in the syste.data.sqlite and system.data.sqlite.ef6

Despite this I can't do model first (project a model and then create a new database from it) because I get another ado.net provider exception.

Any ideas about that?

Thank you Lorenzo

_________________ UPDATE 04-2014 _________________

After some testing and googling... I read that when you want to use the VS design tools you have to install the right x86 version of the SQLite drivers. These drivers, to work properly with the VS tools, needs to register their version of the System.Data.SQLite in the GAC during the installation process (only after this VS knows where to find the connection provider for the design tools). When you use the model-first approach and you ask the model to create the db instead of use the correct driver registered in you app.config it tryes to open the entity connection with the one registered in GAC and used by the visualmodel creation tool (and wich is not compatible). I think there's no way at the moment to use the VS's entity modelling tool with the SQLite provider.

Lorenzo

LoxLox
  • 977
  • 9
  • 16
  • 1
    You no longer need to manually register the SQLite ADO.Net provider in the GAC. There is a build that natively supports VS2013. Go to http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki and search for "Visual Studio 2013". As of today the install is called sqlite-netFx451-setup-bundle-x86-2013-1.0.92.0.exe. – Lee Richardson Mar 31 '14 at 12:10
  • This fix worked for me with sqlite 1.0.92.0 installed via nuget on vs2010. Thanks. – flobadob Jun 22 '14 at 20:29
  • Unfortunately at this time even with version 1.0.92.0 Model First does not work with Visual Studio 2013 and EF6 even using the VS2013 x86 installer from SQLite.org. :( – Rodney S. Foley Aug 28 '14 at 15:40
  • Don't understand, install/uninstall 1.0.94.0 x86 4.5.1 for VS2013 several times but nothing worked for me. No way to create a new data connection for SQLite. – Sebastien GISSINGER Jan 23 '15 at 18:20
0

@LoxLox : I don't think you have to register dll with GAC. I have same problem like yours but I just need to edit the .config file as discussed in this post by adding .EF6 suffix to invariant.

T N
  • 396
  • 5
  • 13