Manually opening an EntityConnection to SQLite database causes ProviderIncompatibleException

c# entity-framework entity-framework-6 sqlite


For integration testing purposes I'd like to manually create and open an EntityConnection in the test fixture set up. This fails with the following exception when calling the Open() method:

System.Data.ProviderIncompatibleException : A null was returned after calling the 'GetService' method on a store provider instance of type 'System.Data.SQLite.EF6.SQLiteProviderFactory'. The store provider might not be functioning correctly.

I'm using the same connection string which is also used when EF takes care about connection opening. If I run the same test suite with automatic connection handling by EF it works.

public void FixtureSetUp()
    // Setup database 
    // Setup data access
    var ec = new EntityConnection([ConnectionString]);
    ec.StoreConnection.Open(); --> WORKS!!
    ec.Open(); -> Throws

The connection string looks like the following:

metadata=res://*/Test.TestModel.csdl|res://*/Test.TestModel.ssdl|res://*/Test.TestModel.msl;provider=System.Data.SQLite;provider connection string="data source=C:\Test\tmp4C80.tmp;read only=False;pooling=False;failifmissing=True;synchronous=Full;datetimekind=Utc;enlist=True;setdefaults=False;datetimeformat=ISO8601;journal mode=Off;cache size=4194304"

The app.config for the NUnit assembly is the following

<?xml version="1.0" encoding="utf-8"?>

        <section name="entityFramework"
                 type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089"
                 requirePermission="false" />
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
            <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" />
    <!-- Register protable database data providers -->
            <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.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6, Version=, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />

Beside NUnit for testing, I'm using Entity Framework 6.1.1 and System.Data.SQLite

Edit: The strange thing is that opening the store connection of the provided entity connection manually works...

10/29/2014 1:33:21 PM

Accepted Answer

I found out that I used the EntityConnection from System.Data.Entity instead of the EntityFramework assembly.

1/21/2015 12:30:29 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow