Manually opening an EntityConnection to SQLite database causes ProviderIncompatibleException

c# entity-framework entity-framework-6 sqlite


I want to manually construct and open an EntityConnection in the test fixture setup for integration testing. When using the Open() method, this fails with the following exception:

System.Data.ProviderIncompatible Exception: When the 'GetService' method was called on a store provider instance of type 'System.Data.SQLite.EF6.SQLiteProviderFactory,' a null was returned. It's possible that the store provider isn't operating properly.

I'm using the exact same connection string that EF uses to handle connection opening. The same test suite runs successfully if EF handles connections automatically.

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

This is how the connection string appears:

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 following is the app.config for the NUnit assembly.

<?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" />

I use System.Data.SQLite and Entity Framework 6.1.1 in addition to NUnit for testing.

The odd thing is that manually establishing the store connection for the specified entity connection works.

10/29/2014 1:33:21 PM

Accepted Answer

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