Geeks With Blogs
Paul's Petrov Whiteboard [BizTalk, Enterprise Application Integration, Business Process Automation, SOA, .NET]

I've been working lately on web application that uses Asp.Net MVC, WordPress and MySQL database. To communicate from .NET code to MySQL database using Entity Framework we installed MySql .NET Connector. It worked fine out of the box on developer's workstations but once deployed to hosted web server application started to throw following error:

[NotSupportedException: Unable to determine the provider name for connection of type 'MySql.Data.MySqlClient.MySqlConnection'.] System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInvariantName(DbConnection connection)
System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
System.Data.Entity.DbSet`1.Add(TEntity entity)

Apparently, somehow MySQL .NET provider was not registered on server although installation was done properly and all assemblies were present in GAC. Since on shared hosting we did not have access to machine.config by adding the same registration entry to the application web.config file resolved the issue:

 

 <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, Version=6.4.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"/> 
    </DbProviderFactories> 
  </system.data>

Important: 

1) Make sure to register the same version that is installed on the server

2) Provide precise fully qualified name in the type attribute. For example, adding extra space between MySql.Data.MySqlClient.MySqlClientFactory and MySql.Data will make this entry useless and will result in the same error

Posted on Sunday, September 11, 2011 11:05 AM .Net | Back to top


Comments on this post: Configure MySql .Net Connector with Entity Framework

No comments posted yet.
Your comment:
 (will show your gravatar)


Copyright © Paul Petrov | Powered by: GeeksWithBlogs.net