how to show mysql provider on mvc (add new cnnection ) dialog - mysql

i have an mvc app
i added all the mysql connectors to the project references
i opened the Package Manager Console and typed "Install-Package MySql.Data.Entity -Pre", and then pressed Enter
then
i replaced this code in the web.config file
<entityFramework>
<providers>
<provider invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity"/>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"></remove>
<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.7.2.0"/>
</DbProviderFactories>
</system.data>
i also added my connection string
<connectionStrings>
<add name="myconn"
providerName="MySql.Data.MySqlClient"
connectionString="[Insert your ConnectionString from Azure here]"/>
</connectionStrings>
now when i go to =>Data Connections =>add connection => change
i cant find mysql provider there
what i have to do to add it in the data sorce there???
thanx for your help :)

You have to install MySQL for Visual Studio to get that provider in the available providers list when adding a new data connection.
https://dev.mysql.com/downloads/windows/visualstudio/1.2.html
a screenshot from my Visual Studio 2015 :

Related

"The provider did not return a ProviderManifestToken string" MySQL with Entity Framework

I have set up a new project in VS 2017. My intention is to use EF CodeFirst approach. So far I used Azure SQL Database, while in this test project I want to use my remote MySQL database. I have created the user and permissions are set just right. This remote database server is accessible to me over MySQL Workbench.
I have created a new blank MVC project and through Nuget I installed MySQL.Data.Entity (version 6.9.10).
My Context class:
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class WebDb : DbContext
{
public WebDb() : base("WebDb")
{
}
public DbSet<Candidate> Candidates { get; set; }
}
My web.config has these entries:
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<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.9.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
And my connection string is:
<connectionStrings>
<add name="WebDb" providerName="MySql.Data.MySqlClient" connectionString="server=x.x.x.x;uid=dbuser;pwd=password;database=temp1;" />
</connectionStrings>
I have a simple domain class
public class Candidate
{
public int Id { get; set; }
public string Name { get; set; }
}
When I give Enable-Migrations -Force command, I get
Checking if the context targets an existing database...
System.Data.Entity.Core.ProviderIncompatibleException: The provider
did not return a ProviderManifestToken string. --->
MySql.Data.MySqlClient.MySqlException: Unable to connect to any of the
specified MySQL hosts. at
MySql.Data.MySqlClient.NativeDriver.Open() at
MySql.Data.MySqlClient.Driver.Open() at
MySql.Data.MySqlClient.Driver.Create(MySqlConnectionStringBuilder
settings) at
MySql.Data.MySqlClient.MySqlPool.CreateNewPooledConnection() at
MySql.Data.MySqlClient.MySqlPool.GetPooledConnection() at
MySql.Data.MySqlClient.MySqlPool.TryToGetDriver() at
MySql.Data.MySqlClient.MySqlPool.GetConnection() at
MySql.Data.MySqlClient.MySqlConnection.Open() at
MySql.Data.MySqlClient.MySqlProviderServices.GetDbProviderManifestToken(DbConnection
connection) at
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection
connection) --- End of inner exception stack trace --- at
System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifestToken(DbConnection
connection) at
MySql.Data.Entity.MySqlManifestTokenResolver.ResolveManifestToken(DbConnection
connection) at
System.Data.Entity.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection
connection, DbProviderManifest& providerManifest) at
System.Data.Entity.DbModelBuilder.Build(DbConnection
providerConnection) at
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext
internalContext) at
System.Data.Entity.Internal.RetryLazy2.GetValue(TInput input) at
System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
at
System.Data.Entity.Internal.LazyInternalContext.get_ModelBeingInitialized()
at System.Data.Entity.Infrastructure.EdmxWriter.WriteEdmx(DbContext
context, XmlWriter writer) at
System.Data.Entity.Utilities.DbContextExtensions.<>c__DisplayClass1.<GetModel>b__0(XmlWriter
w) at
System.Data.Entity.Utilities.DbContextExtensions.GetModel(Action1
writeXml) at
System.Data.Entity.Utilities.DbContextExtensions.GetModel(DbContext
context) at
System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration
configuration, DbContext usersContext, DatabaseExistenceState
existenceState, Boolean calledByCreateDatabase) at
System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration
configuration) at
System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor(DbMigrationsConfiguration
migrationsConfiguration) at
System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.RunCore()
at System.Data.Entity.Migrations.Design.ToolingFacade.BaseRunner.Run()
The provider did not return a ProviderManifestToken string.
I have searched far and wide to the best of my knowledge to no avail. What's happening here? What am I missing?
I've been having the same problems as you recently. Everything worked fine in SQL Server, but I was having lots of problems converting to MySQL. Some things that worked for me are:
Install-Package MySQL.Data -Version 6.9.9
Install-Package MySql.Data.Entity -Version 6.9.10
The newer 8.0 packages of MySQL appear to have problems. When I reverted to an older version, it worked.
Your app.config should look like:
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<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="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.8.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<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.9.10.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
<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.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
</configuration>
Even after that, there are some discrepancies in MySQL that I'm just finding out. For example, your migration "index" statements will not work. You'll have to edit the migration file and build the index yourself. Another thing that I just read, but haven't encountered, is that the MySQL driver does not allow multiple connections which may mean changing the way you retrieve async collections. Lastly, I had a problem with RowVersion being a byte[]. I used a variation from the following article to solve this (hopefully!).
Better way to implement a row version with EF Core and MySQL?

Visual Studio 2015 Entity Framework No connection to MySQL

Had been struggling this for quite sometime. Installed MySQL DB, MySQL .Net Connector and everything that came with MySQL installation. Created a project in VS. Installed MySql.Data and MySql.Entity from Nuget. Tried to create EDMS using ADO model. On the connection popup, no entry for MySql server and no MySql .Net connector in the dropdown.
In web.cofing:
<connectionStrings>
<add name="LocalMySqlServer" connectionString="server=localhost;user id=root;password=mypassword;database=mydb" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
Connectionfactory and other entries in web.config are fine too.
<dependentAssembly>
<assemblyIdentity name="MySql.Data" publicKeyToken="c5687fc88969c44d" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-6.9.9.0" newVersion="6.9.9.0" />
</dependentAssembly>
<entityFramework>
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider></providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" /><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.9.9.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /></DbProviderFactories>
</system.data>
Have repeated instructions provided here Cannot connect to mysql from visual studio 2015 and here Can't Create Entity Data Model - using MySql and EF6 many times but no success. DLLs are referenced correctly.
Any pointers? Is there a log file somewhere that can tell me why MySql connector is not working?

Entityframework wizard crashes Visual Studio 2013

I am trying to create an entityframework 6 model with a mysql database.
I am using the latest mysql server install and have added the Mysql.Data.Entity (24/02/2015) package to the project with nuget manager.
However when I go through the wizard (picking database first), I can connect to the database on the connection page but when I click next I first get a page stating that "an entity framework database provider compatible with this version could not be found for your data connection......"
If I then try to run the wizard again and click next on the connection page the wizard just disappears......
how do I get it to connect? I have always been able to do this without issue so I am baffled as to what is going on......
My App.Config is as follows
<?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>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d">
</provider></providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<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.9.6.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data></configuration>

Entity Framework 6 with MySQL

I'm trying to get Entity Framework 6 to work with a MySQL database. I am following this guide:
http://bitoftech.net/2015/01/21/asp-net-identity-2-with-asp-net-web-api-2-accounts-management/
Where I'm replacing the local database with a MySQL one. I installed the MySQL.NET Connector/Net Nuget package. However, replacing the connection string with that of my host is giving me problems. I can't get the enable-migrations command to work properly. On their FAQ pages, my host states you need to use this connection string:
Server=myServerAddress;Database=MyDataBase;User=MyUser;Password=myPassword
Which led me to this connection string:
<add name="DefaultConnection" connectionString="Server=12.345.6.789:1234;Database=MyDatabaseName;User=MyUserName;Password=MySuperSecretPassword" providerName="System.Data.SqlClient" />
I set the IP and portnumber they gave me as a server. Note the providername. I get this error when running enable-migrations in the console:
An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file. See http://go.microsoft.com/fwlink/?LinkId=386386 for information on DbContext and connections. See the inner exception for details of the failure.
When I switch the providername to MySql.Data.MySqlClient, I get this error:
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.
What am I doing wrong? What's the simplest way to set up a connection to my MySQL database using EF6?
Edit:
My current web.config:
<connectionStrings>
<add name="DefaultConnection" connectionString="Server=x.x.x.x;Database=RademaekAuthentication;User=x;Password=x" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
Inside of your web.config, the entire config is under the tag <configuration>. Anywhere inside of that you need to have
<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" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6" />
</providers>
</entityFramework>
I recently had this problem and solved it with the following connection string:
<add name="DefaultMySqlConnection" providerName="MySql.Data.MySqlClient" connectionString="Data Source=localhost; port=3306; Initial Catalog=<name>; uid=<user>; pwd=<password>;" />
The Web.config also contains the following :
<entityFramework>
<defaultConnectionFactory
type="System.Data.Entity.Infrastructure.SqlConnectionFactory,
EntityFramework" />
<providers>
<provider
invariantName="MySql.Data.MySqlClient"
type="MySql.Data.MySqlClient.MySqlProviderServices,
MySql.Data.Entity.EF6" />
</providers>
And in the system.data tag(create it right before the </configuration> tag if it doesn't exist), add the following code:
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" /><add name="MySQL" description="ADO.Net driver for MySQL" invariant="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data"/>
</DbProviderFactories>
This is my DbContext class:
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class DatabaseContext : DbContext
{
public DatabaseContext(string connectionString)
: base(connectionString)
{ }
After this make sure to run the migrations and it hopefully works.
EDIT: Maybe it's worth mentioning I don't have the <providers> part in my config.

MySql and Entity Framework 6

I am trying to use EF 6 with MySQL and am coming up with this error message going through the connection wizard:
Your project references the latest version of Entity Framework; however an Entity Framework database provider compatible with this version could not be found for your data connection.
Searching the internet it seems this is an issue plaguing people but I can't see that anyone has a solution.
I have references to EntityFramework 6.1.1 and MySql.Data 6.9.3, Mysql.Data.Entity.EF5 and MySql.Data.Entity.EF6 versions 6.8.3. I have also tried it with MySql.Data 6.8.3 but the same thing happens.
My web.config shows the following:
<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 invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
Any thoughts or help would be gratefully received - otherwise I'll have to ditch MySql and go for Sql Server, putting a big hole in my schedule and an even bigger one in my wallet :-).
I have come across the post below, but it doesn;t seem to work for me:
Can't use a MySQL connection for entity framework 6
It looks to me like you have providers for both SQL Server and MySQL and the default connection factory is for the SQL Server provider. Do you need both? If not then you can remove the SQL Server parts altogether and make sure the default connection is MySQL.
Also, I notice that you have not posted the system.data portion of your config file. My working MySQL 6.9.3 config has this section.
My config looks like:
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient" />
<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.9.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
<entityFramework codeConfigurationType="MySql.Data.Entity.MySqlEFConfiguration, MySql.Data.Entity.EF6">
<defaultConnectionFactory type="MySql.Data.Entity.MySqlConnectionFactory, MySql.Data.Entity.EF6" />
<providers>
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.9.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>