SQlite Entity Framework ADO.net provider error 1.0.92.0 - entity-framework

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

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 : 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.

Related

entitiy framework: Multiple Database Providers in single application on single model

I am currently working on an application which was build around EF4 connecting to MSSQL.
Now it was decided, that we should also be able to connect to SQLite.
I've upgraded the application to EF6, made sure everything works as intended with MSSQL and am now trying to get the application to connect to an SQLite DB (which is a converted version of our mssql db).
Sadly I've kinda hit a wall here.
If I try to create the SQLite connection the same way we do for MSSQL
EntityConnectionStringBuilder entityBuilder = new EntityConnectionStringBuilder();
entityBuilder.Provider = "System.Data.SQLite.EF6";
entityBuilder.ProviderConnectionString = "data source=sqlite_master.db";
entityBuilder.Metadata = #"res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl";
connection = new EntityConnection(entityBuilder.ToString());
connection.Open();
theEntities = new masterEntities(connection); // masterEntities extends System.Data.Entity.DbContext
getDataBaseVersion();
I get an Exception stating that "System.Data.SQLite.SQLiteConnection" cannot be converted to "System.Data.SqlClient.SqlConnection" in the getDataBaseVersion Method (which is the first one to run a query on the entities).
I've already tried out a few things, but always got either this or an "unintended code first exception".
Btw: I don't really need to create the connection strings for the SQLite version at runtime. If the problem can be fixed by using the config file, I'll gladly do it.
My app.config looks like this:
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<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" />
</DbProviderFactories>
</system.data>
My guess is that somewhere within the entity data model the data.sqlclient class is set to be used. But I can't create a second Entity Data Model, as then all classes and properties would be definded twice. (I also can't because the sqlite data source won't show up in the assistent for entity data model, but I hope to be able to fix that by reinstalling everything)
Now I wonder: Is it even possible to use two different providers within the same application for the same model?
If yes, I'd be very happy if someone could point me towards a solution to get it working.
Update
I think I've made some progress last night: after adding .EF6 to every System.Data.SQLite in the app.config I now get a different exception.
the app config now looks like this:
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<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>
I now get an exception stating that the provider name for providerfactory "System.Data.SQLite.SQLiteFactory" cannot be found.
I haven't looked into it yet, gonna do so over the course of the day.
-edit-
My project currently references (among others)
EntityFramework.dll // from nuget
EntityFramework.BulkInsert // from nuget
EntityFramework.MappingAPI // from nuget
EntityFramework.SqlServer // from nuget
System.Data
System.Data.DataSetExtensions
System.Data.Linq
System.Data.SQLite // from the sqlite-netFx451-setup-bundle-x86
System.Data.SQLite.EF6 // from the sqlite-netFx451-setup-bundle-x86
Ok, I give up now.
I've now created a DB-First SQLite Model and I get the same exception, just reversed, when trying to connect to it with the MSSQL Provider.
Looks like I will have to use plan B and compile two versions of our application. One for sqlite and one for mssql.

Firebird EF6 DDEX VS2013 Community Update 4 Dynamic SQL Error

I am trying to read data from an old (but live) Firebird database for my company's ERP. Unfortunately, I have very little info about the Firebird database. It was made by someone else, and I'm not permitted to change it due to the conditions of our service & maintenance agreement.
I have set up the DDEX provider and EF6 provider for VS2013 as well as my project. I am attempting to create an EDM for the database. I have this error when running the Entity Data Model Wizard in Visual Studio:
An error occurred while connecting to the database. The database might
be unavailable. An exception of type
'System.Data.Entity.Core.EntityCommandExecutionException' occurred.
The error message is: 'An error occurred while executing the command
definition. See the inner exception for details. The inner exception
caught was of type 'FirebirdSql.Data.FirebirdClient.FbException', with
this error message: 'Dynamic SQL Error SQL error code = -104 Token
unknown - line 6, column 8 SELECT'. The inner exception caught was of
type 'FirebirdSql.Data.Common.IscException', with this error message:
'Dynamic SQL Error SQL error code = -104 Token unknown - line 6,
column 8 SELECT'.'.
Here is my app.config:
<?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" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="FirebirdSql.Data.EntityFramework6.FbConnectionFactory, EntityFramework.Firebird" />
<providers>
<provider invariantName="FirebirdSql.Data.FirebirdClient" type="FirebirdSql.Data.EntityFramework6.FbProviderServices, EntityFramework.Firebird" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="FirebirdSql.Data.FirebirdClient" />
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient" />
</DbProviderFactories>
</system.data>
</configuration>
Here is the relevant section of my machine.comfig:
<system.data>
<DbProviderFactories>
<add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/>
<add name="FirebirdClient Data Provider" invariant="FirebirdSql.Data.FirebirdClient" description=".NET Framework Data Provider for Firebird" type="FirebirdSql.Data.FirebirdClient.FirebirdClientFactory, FirebirdSql.Data.FirebirdClient, Version=4.6.0.0, Culture=neutral, PublicKeyToken=3750abcc3150b00c" />
</DbProviderFactories>
</system.data>
I'm using DDEXProvider-3.0.1.0, and both of its DataTools dll's are loaded into the GAC.
I'm using EntityFramework.Firebird-4.6.0.0-NET45, and the dll, FirebirdSql.Data.FirebirdClient is in the GAC.
I'm using Entity Framework 6.1.2 in my solution from NuGet. (Originally I was using 6.0, but I got the same error.)
I'm using Firebird ADO.NET Data Provider in my solution 4.6.0.0 from NuGet.
I'm using Firebird Entity Framework Provider 4.6.0.0 in my solution from NuGet.
My data connection tests okay, and it is using Dialect 3 to communicate with the database. I have experimented with Dialect 1, but it does not solve the problem. I am currently using "none" for the character set.
In Server Explorer, I can browse all folders: Domains, System Tables, Tables, Views, and Stored Procedures with no error.
In my opinion, the error code suggests the Firebird database doesn't like the "." in column 8 of the command. Does anyone have a solution for this? Has anyone even encountered this problem?
Firebird Version 1.5 is too old to be used with Entity Framework. Use gbak to create a portable backup file (fbk) of your database, update the Firebird server to 2.5.3 and run gbak again to restore the database. Now EF should work for you.

Oracle ODAC 12c Release 3 32-bit beta supports EF 6.x?

I have Windows 8.1 64-bit with Visual Studio 2013. I've installed the latest Oracle ODAC 12c Release 3 32-bit beta which claims to supports EF 6. When I add the ADO.NET Entity Framework to my project and choose my Oracle data connection, it doesn't allow me to select the Entity Framework 6.0 version. It has Entity Framework 5.x selected and version 6.x is greyed out. It says 'An Entity Framework database provider compatible with the latest version of the Entity Framework could not be found for your data connection'. Why is that?
I did the following to make it work :-
First Installing ODAC 12c Release 3 which includes support for Entity Framework 6 Code First and Code First Migrations; NuGet, .NET Framework 4.5.2; and ODP.NET, Managed Driver XML DB. As per
http://www.oracle.com/technetwork/topics/dotnet/whatsnew/index.html
Adding two references , to my project references and they are :
Oracle.ManagedDataAccess.dll
Oracle.ManagedDataAccess.EntityFramework.dll
Installing EF6.1.1 using NuGet by running the following command in Package Manager Console( you can enter it by Tools->NuGet Package Manager -> Package Manager Console):
Install-Package EntityFramework -Version 6.1.1
And modify your web.config or web.config to use Oracle.ManagedDataAccess , by adding Provider and a valid connection string eg :
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="Oracle.ManagedDataAccess.Client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<contexts>
<context type="App.Context.Default, App.Context">
<databaseInitializer type="MyProject.Context.Config.ContextInitializer, MyProject.Context" />
</context>
</contexts>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="Oracle.ManagedDataAccess.Client" type="Oracle.ManagedDataAccess.EntityFramework.EFOracleProviderServices, Oracle.ManagedDataAccess.EntityFramework, Version=6.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="Default" providerName="Oracle.ManagedDataAccess.Client" connectionString="DATA SOURCE=XE;USER ID=User" />
</connectionStrings>
Rebuild your Application as x86, and start using EF6 , you can check if it works by adding a model using ADO.Net Entity Model using Code First
Did you install from this file: ODAC121010Beta2_32bit.zip and then choose to install Oracle Developer Tools?
It is the only file on that page that includes the Oracle Developer Tools for Visual Studio which must be updated for design time EF work.
set Oracle.ManagedDataAccess.EntityFramework.dll Specific version to True and rebuild your app. And then try adding ADO.NET Entity wizard again

entity framework code first migrations from seperate windows class library

i have a solution that contains an MVC project and windows class library project that uses entity framework and is a data access layer. I tried to enable migrations with the following package manager console line
Enable-Migrations -ProjectName PortlandRoad.DAL -ContextTypeName PortlandRoadDBContext -Force
I try to update the database using the following line
Update-Database -Verbose -Force
if i do this with the mvc project as the startup project it works, but uses the connection string in the mvc project web.config. If i do this with the dAL project as the startup project i get the following error :
A file activation error occurred. The physical file name '\PortlandRoadDB.mdf' may be incorrect. Diagnose and correct additional errors, and retry the operation.
CREATE DATABASE failed. Some file names listed could not be created. Check related errors.
the app.config file for my DAL project is as follows :
<?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" />
<!--<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />-->
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=PortlandRoadDB;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\PortlandRoadDB.mdf" providerName="System.Data.SqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>
can anybody tell me how to correct this so that the migrations work specifically for the dal project and are not dependent on the MCV project being the startup project
thanks
I've the same issue in a WPF project.
I think that you have two options.
Option 1
At startup in you windows project try to specify the correct path to your database using
AppDomain.CurrentDomain.SetData("DataDirectory","your\physical\path");
With this, you will have the same error but your migrations can still being applied to your principal database.
option 2
Find a way to replace dynamically this |DataDirectory| in your app.config file before starting your application. (.bat , or .ps or ...).
another option: The bad one.
Before running your migration change the path to you DataDirectory to a physical temporary one in your app.config (this file will help you keep up to date migrations history)
before launching your application replace the temporary file path by |DataDirectory| and change this parameter in your startup with the App.config
With this work around, if your are planning to deploy your application, you will keep track of all migrations in order to anticipate futures database modifications.
VoilĂ .
Could it be that you're using "|DataDirectory|" in the connection string in the DAL project? Since "|DataDirectory|" is an Asp.Net folder and the DAL project is not an Asp project it probably doesn't recognize that as a directory and it probably doesn't exist thing the DAL project.

Entity Framework 5 Code Migration doesn't create database

I'm trying to use Entity Framework 5 Code First.
I've created model classes and context.
After that following Microsoft instructions I've enabled code migrations.
Than I skipped running my application (during which DB should be created first time) and use Add-Migration command. Migration was generated successfully.
Update-Database call was also successfull. But I'm not seeing my DB at all. It is absent!
SQL Management Studio and Visual Studio Server Explorer show only 4 default system databases and that's all!
I also tried to launch my application - it doesn't change anything.
I'm using
public MyContext() : base("name=MyContext") { }
such type of constructor (so I need specify connection string with MyContext name.
Here is my app.config example:
<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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="BettyContext" providerName="System.Data.SqlServerCe.4.0" connectionString="Data Source=MyDB.sdf"/>
</connectionStrings>
</configuration>
I have no idea what's going on. Seems that no one has such problem. May be I've missed some evident thing, but howbeit I'm waiting for some help.
Do you see an exception? If you don't see an exception you probably are not looking at the right database. You can try adding some data to the database with your app and then read it. If the data can be successfully added and read and you still don't see the database it would confirm that you are looking at wrong database.