Manually opening an EntityConnection to SQLite database causes ProviderIncompatibleException

c# entity-framework entity-framework-6 sqlite system.data.sqlite

Question

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.

...
[TestFixtureSetUp]
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"?>

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

I use System.Data.SQLite 1.0.94.0 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.

1
2
10/29/2014 1:33:21 PM

Accepted Answer

ZZZ_tmp
1
1/21/2015 12:30:29 PM


Related Questions





Related

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