code first -The provider did not return a ProviderManifestToken string - exception

I wrote a windows form solution with 2 layers; one is DataAccess and the other is windows form.
I use Code first. If DataAccess Layer runs in the application console, there is no problem with the db. Create the schema and insert the data.
However, when I run the solution with Windows Form as the initial project and refer to DataAccess as a dll, I cannot build the database. It throws an exception.
I think that the app.config file is the problem, but if I copy the app.config file of DataAccess project to the windows form, it does not resolve the problem.
the config file of DataAcces layer:
<?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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
the exception:
"first exception for 'System.Data.Entity.Core.ProviderIncompatibleException' in EntityFramework.dll
Aditional Information: An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct."
Inner Exception:
{"The provider did not return a ProviderManifestToken string."}

The problem could be due to Error in connection string
or in my case it was that
SQL server service was not running
manually start the SQL service through SQL SERVER COnfiguration Manager

after a long deep search, i found that solution was "clean the solution".

Related

Visual Studio 2015 Only Shows SQL Server Connections When Trying to Create an ADO.NET Entity Model Class

I have previously created an instance of a MySQL database as described in this question on Code Review. I have completed the database, and I’m ready to create the application using C# in Visual Studio 2015.
The only question I’ve found here on stackvoverflow.com that seems relevant is this one.
I have been using MySQL Documentation from these pages:
Connector Instalation using Nuget
Connector / NET Entity Framework 6.0
Environment is Windows 10, The regedit image shows the .net framework version. I upgraded MySQL to version 8.0.11 earlier this week.
Package Manager Console:
PM> get-package
Id Versions ProjectName
-- -------- -----------
EntityFramework {6.2.0} bkInventory2App
Google.Protobuf {3.5.1} bkInventory2App
MySql.Data {8.0.11} bkInventory2App
MySql.Data.EntityFramework {8.0.11} bkInventory2App
App.config
<?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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<connectionStrings>
<add name="MySQLBKLibInventory" providerName="MySql.Data.MySqlClient" connectionString="SERVER=localhost;DATABASE=pacswlibinvtool;UID=root;PASSWORD=******;" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, EntityFramework"/>
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"/>
<!-- provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" -->
</providers>
</entityFramework>
</configuration>
Dot Net Version
Add ADO.NET Class
Choose Model Contents
Choose Data Connection
Choose Data Source
ODBC Data Administrator
Installed MySQL Applications
Database in MySQL WorkBench
Please note in the second to last image, the one showing the installed MySQL Applications, that MySQL for Visual Studio is not installed. Installing MySQL Visual Studio corrected this particular configuration problem.

Error 175: The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is not registered

I know there are similar questions that have been asked, but most are related to Entity Framework or have been left unanswered. So please do not mark as Duplicate just by the title.
I have an issue with a VB.NET application, following an upgrade of the users machine (to Windows8 64-bit OS).
In fact, when I open the source code to rebuild the application, I get the Error 175 coming from the edmx file:
The ADO.NET provider with invariant name 'MySql.Data.MySqlClient' is
either not registered in the machine or application config file, or
could not be loaded.
I checked a bit online but almost all the answers refers to Entity Framework.
MySQL Connector 6.1.6 has been installed and the corresponding reference MySQL.data has been added, yet I cannot clear the error.
Error goes from this line of my edmx file, when the Provider is called;
<edmx:StorageModels>
<Schema Namespace="tci_db_01Model.Store" Alias="Self" Provider="MySql.Data.MySqlClient" ProviderManifestToken="5.1" xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" xmlns="http://schemas.microsoft.com/ado/2006/04/edm/ssdl">
<EntityContainer Name="db_01ModelStoreContainer">
<EntitySet Name="tb0001_nitg" EntityType="db_01Model.Store.tb0001_nitg" store:Type="Tables" Schema="db_02" />
ConnectionString in the app.config file is as follows;
</connectionStrings>
<system.data>
<DbProviderFactories>
<clear />
<add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=6.6.5.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
Has anyone ever encountered this issue? How do I clear the error?

Using MSSQL and MySQL database both as entity framework 6 model

I'm new to work with MySQL with asp.net and I'm trying to use asp.net mvc 4 and entity framework 6 to view datas from MySQL & MSSQL database both. So far MSSQL is working fine. But whenever I try to view datas from MySQL tables I get this error,
Schema specified is not valid. Errors: Models.MySqlModel.ssdl(2,2) : error
0152: No Entity Framework provider found for the ADO.NET provider with
invariant name 'MySql.Data.MySqlClient'. Make sure the provider is registered
in the 'entityFramework' section of the application config file. See
http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
I've installed MySQL for Visual Studio 1.1.4 & MySQL Connector .NET 6.8.3, I've added MySql.Data, MySql.Data.Entity.EF5, MySql.Data.Entity.EF6 assemblies in the reference folder. This is my Web.Config code for db connection,
<connectionStrings>
<add name="DefaultConnection" providerName="System.Data.SqlClient" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-ABCoLtd-20150101142609;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-ABCoLtd-20150101142609.mdf" />
<add name="mytestdbEntities" connectionString="metadata=res://*/Models.SampleModel.csdl|res://*/Models.SampleModel.ssdl|res://*/Models.SampleModel.msl;provider=System.Data.SqlClient;provider connection string="data source=DREAGLEASUS64\SQLEXPRESS;initial catalog=mytestdb;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /><add name="mdsdata_demoEntities" connectionString="metadata=res://*/Models.MySqlModel.csdl|res://*/Models.MySqlModel.ssdl|res://*/Models.MySqlModel.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=root;password=4de570;database=mdsdata_demo"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
Code from Controller to view data from MySQL table,
namespace ABCoLtd.Controllers
{
public class HomeController : Controller
{
mytestdbEntities db = new mytestdbEntities(); //MSSQL Model
mdsdata_demoEntities dsedb = new mdsdata_demoEntities(); //MySQL Model
public ActionResult InstrumentList()
{
return View(dsedb.mkistats.ToList()); //The Line showing error
}
}
}
Am I doing something wrong here? I need this help badly. Please help me, your help will be really appreciated. Tnx.
UPDATE
When I see them in Reference Manager it says 6.8.3.0 but in Properties I get 6.8.4.0. Is it the possible bug? If it is, what is the solution? See the images below,
Check if you installed correct bit version and enable 32-bit applications in IIS.
And try to delete one of either references

MySql Connector with EF 6

I am having a weird issue with MySql Connector(6.8.3) and EF6. I was working on a WebApi project where I use MySql and EF6 with Database first approach. Everything worked fine[even deployed on one of the test servers] until I changed the database from 'Test' database to 'Production' database [just the database name] in the connection string and updated the model[just to see nothing is broken!]. After that, it failed to connect to database. So, I changed the connection string back and rebuilt the solution, then I got bunch of 'Mapping' warnings. I deleted the model and tried to create the model again from the database. Now, I am getting the following message
Your project references the latest version of Entity Framework;
however, an Entity Framework database provider compatible with this
version could not be found for you data connection. Exit this wizard,
install a compatible provider, and rebuild your project before
performing this action
Here is the config file
<!-- 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>
<clear/>
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySql.Data.MySqlClient" description="ADO.Net driver for MySQL" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data,Version=6.8.3.0, Culture=neutral,PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
I tried reinstalling the connector and EF from Nuget, but nothing changed. Can someone please let me know whats going on?
Thanks
I had a similar issue, I had the MySql connector referenced to my project with Nuget. But the server had another version of MySql connector installed in the machine itself. So the application gave priority to the MySql connector installed in GAC of server.
All you have to do is either
Uninstall the MySql connector in Server
or
Install suitable MySql connector (in your case v6.8.3) in server and uninstall the rest
or
change your provider type version to one that is installed in the server.
Bloody hell, had the same issue.
I'm pretty new to the .NET environment so, I don't know how the packages manager and all work but it seems that when I import the assemblies for the MySQL connector, it updates the "web.conf" file with the wrong parameters for the provider.
In my case, using EF6 and MySQL Connector for EF v6.8.3.0, the following worked for me :
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6"></provider>
</providers>
</entityFramework>
Hope it helps someone
i know what the problem is, you have to do the next steps :
1. Right click on the project
2. Manage NuGet Packages
3.remove the MySql.Data
4.now you can do what you wanted to do
5.after you finish, go back to Manage NuGet Packages and add MySql.Data.Entity
:)
good luck
nofar eliasi

Linqpad Error with EF DbContext: The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception

I happily run LinqPad 4.47.02 on a Win7 machine. I tried to add a EF5/dbContext connection. I choose my assembly, the class within the assembly and such assembly's config file. When I add the connection, i get this error:
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw
an exception.
My app.config contains this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.data>
<DbProviderFactories>
<add name="MySQL Data Provider"
invariant="MySql.Data.MySqlClient"
description=".Net Framework Data Provider for MySQL"
type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data" />
</DbProviderFactories>
</system.data>
<configSections>
<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="FipavContextContainer" connectionString="metadata=res://*/FipavContext.csdl|res://*/FipavContext.ssdl|res://*/FipavContext.msl;provider=MySql.Data.MySqlClient;provider connection string="server=127.0.0.1;User Id=root;database=fipavmanagerdb"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
</entityFramework>
</configuration>
I tried to comment the tag in configfile as suggested here but i get the same error.
As a side note, the connection worked and I have many saved linqpad queries. When I try to load and run one of them, linqpad crashes with no additional info.
What am I doing wrong?
Thank you,
F.
(weird) SOLUTION:
I tried moving the <configSections> tag just before <system.data> tag and the error flied away
As per msdn article for configSections element:
If this element is in a configuration file, it must be the first child element of the configuration element
I believe that one of the reasons is that this element defines handlers to handle custom sections in the config so if it is first you don't need to read parse config multiple time to handle a case where a custom section is defined before the handler for this section is defined.