7

我正在使用 Entity Framework 5 开发 ASP.NET MVC4 应用程序,并且我使用的是模型优先模式。

但是,如果我使用设计器生成的连接字符串,Simple Membership 将引发以下错误:

    ......
  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" />
4

1 回答 1

6

是的,SimpleMembership 仅适用于 SQL Server 连接字符串,因此您需要在 web.config 中添加这样的条目。不理想,但它就像你说的那样工作......

这可能是您的答案:使用 SimpleMembership 和 EF 模型优先

Jon Galloway 的文章是有关 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

于 2013-03-09T11:35:30.270 回答