ASP.NET Identity with MySql problem after publishing to IIS server - mysql

I made a ASP.NET Web Api. I have my connection string inside web.config and it looks like this:
<add name="AuthContext" connectionString="Data Source=*****; Initial Catalog=*****;Uid=*****;Pwd=****;SslMode=None;" providerName="MySql.Data.MySqlClient" />
This database is also on external server and can be reached from anywhere.
On my local machine everythings works completely fine, but when i publish it to exteral IIS server i get that error:
"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. See the inner exception for details.",
and also this:
"InnerException": {
"Message": "An error has occurred.",
"ExceptionMessage": "Unable to find the requested .Net Framework Data Provider. It may not be installed.",
"ExceptionType": "System.ArgumentException",
"StackTrace": " at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)\r\n at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key, Func`3 handleFailedLookup)"
}
I would like to know why during connecting to dabase with for example ADO.NET i have to use
SslMode=None
In other case i get that error:
it means handshake failed, unexpected package format
Also i get another error in another controller and also only in IIS:

Alright, so in my web.config i added:
<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=8.0.13.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
</DbProviderFactories>
</system.data>
and than everything worked fine

Related

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

Entity framework with MySQL

hello i installed MySQL Connector/Net 6.7.4 so i was able to generate edmx from my MySql database, but now i wanna do smth with it so i added connetion string and :
<DbProviderFactories>
<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.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
in my webconfig, but when i create context(pure generated by .tt) i got an exception on collection:
The specified store provider cannot be found in the configuration, or is not valid.
Any ideas why? I already added MySql.xxx dlls to my bin
Edit: connstring was wrong when i modified provider name so it looks now:
<connectionStrings>
<add name="classicmodelsEntities" connectionString="metadata=res://*/mysql.Model1.csdl|res://*/mysql.Model1.ssdl|res://*/mysql.Model1.msl;provider=MySql.Data.MySqlClient;provider connection string="server=localhost;user id=root;password=Password;persist security info=True;database=classicmodels"" providerName="MySQL Data Provider"/>
i got exception :Unable to find the requested .Net Framework Data Provider. It may not be installed.
If you are using Entity Framework, why are you adding a connection string? The connection string generated for me was different:
<add name="stuffEntities"
connectionString="metadata=res://*/Entities.MyModel.csdl|res://*/Entities.MyModel.ssdl|res://*/Entities.MyModel.msl;provider=MySql.Data.MySqlClient;provider connection string="server=myserver.com;user id=my_user;password=my_password;persistsecurityinfo=True;database=db_example""
providerName="System.Data.EntityClient" />
Add your MySQL references on References, with True for Local copy. Also add the required configuration in Web.config, installing through NuGet the missing package.
To do this, right click your solution or project, click on Manage NuGet packages, and install the missing MySQL.Data reference. This should modify your Web.config with the reference.

MySQL Connector/Net error when not in full trust

I get the following error when running my MVC asp.net (.net 4.0) website on my hosting provider's server:
Attempt by method 'MySql.Data.MySqlClient.MySqlClientFactory.System.IServiceProvider.GetService(System.Type)' to access field 'MySql.Data.MySqlClient.MySqlProviderServices.Instance' failed.
The following should be known about this application:
It uses the entity framework. The hosting provider put a test .aspx
page on my website which does not use the entity framework which can
connect to the database.
The website works on my localhost, except
when I use their trust policy config file. In which case I get the
same error.
It worked before they did some updates, which included adding the SecurityClass MySqlClientPermission
I have searched for solutions, but found only answers to other problems with mysql connector. To show that these are not the issue I include those here:
This in included in the web.config:
<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.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" /> </DbProviderFactories>
They did include this in the trust config:
<SecurityClass Name="MySqlClientPermission" Description="MySql.Data.MySqlClient.MySqlClientPermission, MySql.Data, Version=6.5.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
<IPermission class="MySqlClientPermission" version="1"> <add connectionString="Server=;Database=;User=;Password=;Port=;Pooling=;" restrictions="" KeyRestrictionBehavior="PreventUsage" />
</IPermission>
Perhaps someone can point me in the right direction, because after trying a lot of things I am at a loss.

Cant get my connection to a MySQL from asp.net mvc project to work

I am trying to get MVC 3 Application to use a MySql database, but I keep getting errors, I have made the following connectionstring and provider in my Web.Config file
<connectionStrings>
<add name="DefaultConnection" connectionString="server=xxxxx.unoeuro.com; userid=xxxxx_dk;password=xxxxx;pooling=yes;Database=xxxxx_dk_db" providerName="MySql_db"/>
</connectionStrings>
<system.data>
<DbProviderFactories>
<add name="MySql_db" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.1.54.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
But when I try to use it (Just trying to use the default register user that is in a default project) I get this error
An error occurred creating the configuration section handler for
system.data: Column 'InvariantName' is constrained to be unique.
Value 'MySql.Data.MySqlClient' is already present.
But I if I remove the DbProviderFactories I just get an error that there is missing a data provider, so its not becuase I duplicated it anywhere
Building upon #Ladislav Mrnka's answer, the error is probably occurring because the setting in Web.config is conflicting with one in machine.config. To eliminate the error, add a "remove" tag to your Web.config as follows.
<system.data>
<DbProviderFactories>
<remove invariant="MySql.Data.MySqlClient"/>
<add name="MySql_db" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.1.54.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/>
</DbProviderFactories>
</system.data>
Provider name in connection string must be set to invariant name of provider factory. Also the error most probably says that you already have MySql.Data.MySqlClient installed on your machine and registered in Machine.config.
Install the latest version of MySQL for visual studio and find a compatible version for Connector/NET.
For example, I have used MySQL for Visual Studio 1.2.7. and Connector/NET 6.7.5, 6.8.3 or 6.9.x. for Visual Studio 2013
uninstall all the other versions of MySQL for visual studio and Connector/NET.
After that Add new item-> ADO.Net Entity Data Model and create the edmx file.
you can see system.data and system.data.entity in your reference folder of the project.
In your code
MyDatabaseEntities myDB = new MyDatabaseEntities();
use myDB to access your data.
If you are creating a framework project, copy everything under tag from app.config and paste it into your main project's(startup project) web.config file
One thing needs to keep in mind that this tag should be the first child of tag.