How to configure MvcMusicStore .Net WebApp with MySQL?

Jun 30, 2012 at 4:35 PM

I'm completely lost. I'm trying to setup the MvcMusicStore .Net app (http://mvcmusicstore.codeplex.com/) with MySQL but I got several errors when I compile the project;

I've read the documentation at http://dev.mysql.com about using .Net Entity Framework with MySQL however I'm a beginner with EF and those are the steps that I've made without success:

  • I ve already installed MySQL Server 5.5

  • downloaded MvcMusicStore at http://mvcmusicstore.codeplex.com/downloads/get/238258

  • installed MySQL Connector Net 6.4.4 and created db in mysql: CREATE DATABASE mvcmusicstore /*!40100 CHARACTER SET utf8 COLLATE utf8_general_ci */;

  • added following references to the project MvcMusicStore: mysql.data, (mysql.data.cf not added or i get an error), mysql.data.entity, mysql.web (for each library, in the properties, selected "true" to copy the dll in the bin folder)

  • in "web.config" replaced:

    <connectionStrings>
    <add name="MusicStoreEntities"
    connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
    providerName="System.Data.SqlServerCe.4.0"/>
    </connectionStrings>
    

with:

    
<connectionStrings>
    <add name="MusicStoreEntities"
    connectionString="Server=127.0.0.1; Database=mvc_store; Uid=root; Pwd={* my password *};"
    providerName="MySQL Data Provider" />
    </connectionStrings>
    <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.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>
    </system.data>

  • cleaned project -> compiled & recompiled, then I got the 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."

so I ve replaced the "dbproviderfactories" section with the code found at How to use MySql and Entity Framework 4.1 code first

    
<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.4.4.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
    </DbProviderFactories>

  • recompiled, then I got the error "cannot find the data provider":

    Details:
    ArgumentException: Can not find the data provider. Net Framework required. It may not be installed.
    
    Error in the source code:
    
    Row 17:         ' the albums with the highest count
    Row 18:
    Row 19:         Return storeDB.Albums.OrderByDescending(Function(a) a.OrderDetails.Count()).Take(count).ToList()
    Row 20:     End Function
    Row 21: End Class
    
    File: C:\{...}\MvcMusicStore-Completed\MvcMusicStore\Controllers\HomeController.vb    Row: 19
    
    stack:
    
    [ArgumentException: Can not find the data provider. Net Framework required. It may not be installed.]
    System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1420503
    System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name) +393
    System.Data.Entity.Internal.LazyInternalConnection.Initialize() +47
    System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel() +9
    System.Data.Entity.Internal.LazyInternalContext.InitializeContext() +262
    System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType) +18
    System.Data.Entity.Internal.Linq.InternalSet`1.Initialize() +63
    System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext() +15
    System.Data.Entity.Infrastructure.DbQuery`1.System.Linq.IQueryable.get_Provider() +37
    System.Linq.Queryable.OrderByDescending(IQueryable`1 source, Expression`1 keySelector) +66
    MvcMusicStore.HomeController.GetTopSellingAlbums(Int32 count) in C:\Users\Max\Desktop\Projects\MvcStore\MvcMusicStore-Completed\MvcMusicStore\Controllers\HomeController.vb:19
    MvcMusicStore.HomeController.Index() in C:\Users\Max\Desktop\Projects\MvcStore\MvcMusicStore-Completed\MvcMusicStore\Controllers\HomeController.vb:10
    lambda_method(Closure , ControllerBase , Object[] ) +96
    System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters) +17
    System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters) +208
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +27
    System.Web.Mvc.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12() +55
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation) +263
    System.Web.Mvc.<>c__DisplayClass17.<InvokeActionMethodWithFilters>b__14() +19
    System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodWithFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor, IDictionary`2 parameters) +191
    System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
    System.Web.Mvc.Controller.ExecuteCore() +116
    System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
    System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
    System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
    System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
    System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
    System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
    System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
    System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
    System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
    System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
    System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
    System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8970061
    System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
    --------------------------------------------------------------------------------
    Microsoft .NET Framework:4.0.30319; ASP.NET:4.0.30319.272 
    

I don't know what to do to resolve it.

Thank You in advance,

Max

Coordinator
Jul 2, 2012 at 3:37 AM

Max, I haven't tried using MySQL with EF Code First. Some readers have posted about how they've gotten it to work - http://mvcmusicstore.codeplex.com/discussions/249270