2011-07-28 87 views
45

我正在關注ASP.NET MVC 3音樂商店應用程序教程,但我一直陷入第4部分:http://www.asp.net/mvc/tutorials/mvc-music-store-part-4。它不斷告訴我,我沒有安裝SQL數據提供:無法找到請求的.Net Framework數據提供程序。它可能沒有安裝。 - 當遵循mvc3 asp.net教程

確切錯誤:

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: 

我已經加入了參考System.Data.SqlServerCe - 仍然有同樣的錯誤。任何指導將非常感謝

+2

我會檢查拼寫,並確保它是'System.Data.SqlServerCe.4.0'。如果您還沒有安裝它,也http://www.microsoft.com/download/en/details.aspx?id=17876。 – Buildstarted

+0

是的拼寫正確.. – michelle

+0

您是否嘗試過重新安裝SQL Server CE?過去我曾經遇到過很多問題,即使是修理也不行。卸載(如果您使用的是64位操作系統,則爲32位和64位版本)並重新安裝。 –

回答

30

我能夠通過使用NuGet在Visual Studio 2010中解決類似於此的問題。

轉到工具>庫包管理器>管理的NuGet軟件包的解決方案......

在對話框中,搜索「EntityFramework.SqlServerCompact」。你會發現一個包含描述「允許SQL Server Compact 4.0與Entity Framework一起使用」的包。安裝這個軟件包。

類似如下的元素將被插入在你的web.config:

<entityFramework> 
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework"> 
    <parameters> 
     <parameter value="System.Data.SqlServerCe.4.0" /> 
    </parameters> 
    </defaultConnectionFactory> 
</entityFramework> 
+1

這正是我所缺少的,雖然我確實安裝了ef.sqlservercompact軟件包但它並沒有更新我的web.config – andryuha

+0

這就是我遵循的確切過程,以便讓我的解決方案能夠編譯爲音樂商店教程 – Purusartha

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

+1

可能還需要添加' 'to'machine .config'。 http://forum.linqpad.net/discussion/371/entity-framework-oracle-unable-to-find-the-requested-net-framework-data-provider-it-may-not-be – mbrownnyc

+1

@mbrownnyc太懶了挖掘machine.config。 Web.config已經打開,我粘貼了代碼,它工作!謝謝。事實證明,我有多個SqlCE版本安裝,所以我不需要安裝任何。 – jokab

0

對我來說,這個問題是由連接問題到SQL數據庫造成的。我剛斷開連接,然後重新連接設計視圖中的SQL數據源。我正在恢復運行。希望這適用於每個人。

0

我有一個similer問題上的SqlClient WCF服務。 我的解決辦法是把在客戶端線的app.config

<startup> 
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /> 
    </startup> 

希望它能有助於爲別人..

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> 

更改提供者從MySQL到SQL Server或任何您要連接的數據庫提供者。

0

這發生在我身上,因爲我創建了一個試圖使用System.Web.ProvidersDefaultMembershipProvider作爲成員資格的新項目。我的數據庫和應用程序已設置爲使用System.Web.Security.SqlMembershipProvider。我必須更新提供程序和連接字符串(因爲此提供程序似乎有一些奇怪的連接字符串要求)才能使其工作。

0

我有以下MvcMusicStore教程時同樣在第4部分,取而代之的是這個給定的連接字符串:

添加名稱=「MusicStoreEntities」 的connectionString =「數據源= \ SQLEXPRESS;集成安全性= SSPI; database = MvcMusicStore; User ID = sa; password =「 providerName =」System.Data.SqlClient「/>

它爲我工作。

1

這個錯誤主要是由於與框架安裝EI 86 VS 64 解決方案架構處理器不兼容: 轉到解決方案資源管理器>項目屬性>編譯選項卡>高級編譯選項 你有到目標CPU的X64改變X86 保存新的設置並重新編譯您的解決方案。 我試過了,它工作得很好。 希望這會幫助你。 Malek

相關問題