无法找到请求的.Net Framework数据提供程序.它可能没有安装. - 当关注mvc3 asp.net教程时

mic*_*lle 45 sql-server asp.net-mvc dataprovider asp.net-mvc-3

我正在关注ASP.NET MVC 3音乐商店应用程序教程,但我一直陷入第4部分:http://www.asp.net/mvc/tutorials/mvc-music-store-part-4.它一直告诉我我没有安装SQL数据提供程序:

确切的错误:

System.ArgumentException was unhandled by user code
  Message=Unable to find the requested .Net Framework Data Provider.  It may not be installed.
  Source=System.Data
  StackTrace:
       at System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)
       at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name)
       at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
       at System.Data.Entity.Internal.LazyInternalConnection.get_ConnectionHasModel()
       at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
       at System.Data.Entity.Internal.InternalContext.Initialize()
       at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
       at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
       at System.Data.Entity.Internal.Linq.InternalSet`1.GetEnumerator()
       at System.Data.Entity.Infrastructure.DbQuery`1.System.Collections.Generic.IEnumerable<TResult>.GetEnumerator()
       at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
       at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
       at MusicApplication.Controllers.StoreController.Index() in C:\Users\Michelle\documents\visual studio 2010\Projects\MusicApplication\MusicApplication\Controllers\StoreController.cs:line 18
       at lambda_method(Closure , ControllerBase , Object[] )
       at System.Web.Mvc.ActionMethodDispatcher.Execute(ControllerBase controller, Object[] parameters)
       at System.Web.Mvc.ReflectedActionDescriptor.Execute(ControllerContext controllerContext, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethod(ControllerContext controllerContext, ActionDescriptor actionDescriptor, IDictionary`2 parameters)
       at System.Web.Mvc.ControllerActionInvoker.<>c__DisplayClass15.<InvokeActionMethodWithFilters>b__12()
       at System.Web.Mvc.ControllerActionInvoker.InvokeActionMethodFilter(IActionFilter filter, ActionExecutingContext preContext, Func`1 continuation)
  InnerException: 
Run Code Online (Sandbox Code Playgroud)

我添加了对System.Data.SqlServerCe的引用 - 仍然有相同的错误.任何指导都会非常感激

小智 31

通过使用NuGet,我能够在Visual Studio 2010中解决类似的问题.

转到工具>库包管理器>管理解决方案的NuGet包...

在对话框中,搜索"EntityFramework.SqlServerCompact".您将找到一个包含描述"允许SQL Server Compact 4.0与实体框架一起使用"的包.安装此软件包.

将在您的web.config中插入与以下内容类似的元素:

<entityFramework>
  <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
    <parameters>
      <parameter value="System.Data.SqlServerCe.4.0" />
    </parameters>
  </defaultConnectionFactory>
</entityFramework>
Run Code Online (Sandbox Code Playgroud)


小智 16

我遇到过同样的问题.我在C:\ Windows\assembly中检查了System.Data.SqlServerCe的版本.这是3.5.1.0.所以我从下面的链接(x86)安装了4.0.0版,工作正常.

http://www.microsoft.com/download/en/details.aspx?id=17876


小智 10

将这些行添加到web.config文件中:

<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.6.4.0, Culture=neutral, PublicKeyToken=C5687FC88969C44D"/>
    </DbProviderFactories>
</system.data>
Run Code Online (Sandbox Code Playgroud)

将您的提供程序从MySQL更改为SQL Server或您要连接的任何数据库提供程序.