我完全迷失了。 我正在尝试使用MySQL设置MvcMusicStore .Net应用程序(http://mvcmusicstore.codeplex.com/),但在编译项目时遇到了一些错误;
我已经阅读了http://dev.mysql.com关于在MySQL中使用.Net Entity Framework的文档,但我是EF的初学者,这些都是我没有成功的步骤:
我已经安装了MySQL Server 5.5
安装了MySQL Connector Net 6.4.4并在mysql中创建了db:
CREATE DATABASE mvcmusicstore
/ *!40100 CHARACTER SET utf8 COLLATE utf8_general_ci * /;
在对项目MvcMusicStore的引用之后添加: mysql.data,(没有添加mysql.data.cf或者我收到错误),mysql.data.entity,mysql.web (对于每个库,在属性中,选择“true”以复制bin文件夹中的dll)
在“web.config”中取代:
<connectionStrings>
<add name="MusicStoreEntities"
connectionString="Data Source=|DataDirectory|MvcMusicStore.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
</connectionStrings>
使用:
<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>
“为system.data创建配置节处理程序时出错: 列'InvariantName'被约束为唯一的。 值'MySql.Data.MySqlClient'已存在。“
所以我用“{3}}
中的代码替换了”dbproviderfactories“部分 <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>
重新编译,然后我收到错误“无法找到数据提供者”:
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
我不知道如何解决它。
提前谢谢你,
最高
答案 0 :(得分:0)
您是否还记得在项目中添加对MySQL连接器的引用?