2013-03-09 14 views
7

我正在使用實體框架5開發ASP.NET MVC4應用程序,並且使用模型優先模式。如果我使用由設計器生成連接字符串如果使用實體連接字符串(適用於SQL連接字符串),ASP.NET MVC4簡單成員資格初始化失敗

然而簡單的會員資格會引發以下錯誤:由設計器生成

...... 
    InnerException: System.InvalidOperationException 
    HResult=-2146233079 
    Message=The ASP.NET Simple Membership database could not be initialized. For more information, please see http://go.microsoft.com/fwlink/?LinkId=256588 
    Source=STD 
    StackTrace: 
     at SistemTempahanDewan.Filters.InitializeSimpleMembershipAttribute.SimpleMembershipInitializer..ctor() in c:\Users\Orang\Documents\Visual Studio 2012\Projects\STD\STD\Filters\InitializeSimpleMembershipAttribute.cs:line 45 
    InnerException: System.ArgumentException 
     HResult=-2147024809 
     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 WebMatrix.Data.DbProviderFactoryWrapper.CreateConnection(String connectionString) 
    .... 

連接字符串(無效):

<add name="STD" connectionString="metadata=res://*/Models.STD.csdl|res://*/Models.STD.ssdl|res://*/Models.STD.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.\SQLEXPRESS;initial catalog=STD;integrated security=True;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" /> 

連接字符串我手動添加(將工作):

<add name="STD" providerName="System.Data.SqlClient" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=STD;Integrated Security=True;MultipleActiveResultSets=True" /> 
+0

在程序集中是否有對EF和System.Data.Entity的引用? – 2013-03-09 11:32:58

+0

@NeilThompson它可以與其他一切(查看,編輯,創建,刪除)數據一起工作。只有簡單會員不會。 – 2013-03-09 11:55:05

回答

5

是,Simp leMembership僅適用於SQL Server連接字符串,因此您需要在web.config中輸入這樣的條目。不理想,但它的工作原理就像你說的......

這可能是你的答案:Using SimpleMembership with EF model-first

喬恩·加洛韋的文章是關於SimpleMembership信息的絕佳資源,如果你還沒有已經看過了:http://weblogs.asp.net/jgalloway/archive/2012/08/29/simplemembership-membership-providers-universal-providers-and-the-new-asp-net-4-5-web-forms-and-asp-net-mvc-4-templates.aspx

+0

那麼這是設計還是錯誤?現在我將保留2個連接字符串,因爲缺少其他更簡單的解決方案。 – 2013-03-11 15:38:44

+0

就我個人而言,我認爲它剛剛不受支持,因爲各種技術「聚在一起」(請參閱​​http://odetocode.com/Blogs/scott/archive/2012/09/23/perils-of-在-mvc4-accountcontroller.aspx)。希望它會帶來未來版本! – 2013-03-11 15:43:25

+1

我很高興知道我沒有做錯什麼。希望這可以在下一個版本中得到平滑。感謝您的鏈接! – 2013-03-12 02:28:29