SimpleMembershipInitializer不会初始化 [英] SimpleMembershipInitializer won't initialize

查看:100
本文介绍了SimpleMembershipInitializer不会初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我与得到一个simplemembership场景在我的EntityFramework / MVC4 / DatabaseFirst项目工作的挣扎。我发现很多例子为先用code工作,但没有对DB第一位。

I am struggling with getting a simplemembership scenario working in my EntityFramework / MVC4 / DatabaseFirst project. I've found plenty of examples for working with code first, but nothing for DB first.

我遇到的问题是在InitializeDatabaseConnection抛出一个错误,code看起来像这样(无法找到所需的.NET Framework数据提供它可能没有安装。):

The problem I'm encountering is the the InitializeDatabaseConnection is throwing an error ("Unable to find the requested .Net Framework Data Provider. It may not be installed.") The code looks like this :

WebSecurity.InitializeDatabaseConnection("DALEntities", "tblContacts1", "ContactID", "EMail", autoCreateTables: true);

我不知道是什么的DataProvider失败。如果我试图追溯进的InitializeDatabaseConnection电话,立即引发错误。

I am not sure what DataProvider is failing. If I try to trace 'into' the InitializeDatabaseConnection call, it immediately throws the error.

我是什么失踪?

信息:结果
DALEntities是EF的其余部分使用的connectionString的名称。下面code的作品就好......

Info:
DALEntities is the name of the connectionString that the rest of EF uses. The following code works just fine....

    public ActionResult Test() {
        using (var db = new DALEntities()) {
            var query = from i in db.TBLINVENTORies
                            orderby i.ITEMNAME
                            select i;
            var cnt = query.Count();
            string str = "Total Inventory: " + cnt;
            return Content(str);
        }
    }

我的连接字符串从web.config部分:

My connection strings section from the web.config:

  <connectionStrings>
    <add name="DALEntities" connectionString="metadata=res://*/DAL.DAL.csdl|res://*/DAL.DAL.ssdl|res://*/DAL.DAL.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=SOMECOMPUTER;initial catalog=SOMEDB;persist security info=True;user id=SOMEID;password=SOMEPASS;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>

这个职位似乎是问同样的问题(但在模型的第一个方面),但没有解决尚未:的使用SimpleMembership与EF模型的第一

This post seems to be asking the same question (but in context of model-first), but there is no solution yet : Using SimpleMembership with EF model-first

另外,我看到有对 WebSecurity.InitializeDatabaseConnection过载()的帮助文本:初始化会员制((等等等等&LT;&剪断GT;的ProviderName:ADO.NET的数据提供者的名称如果要使用Microsoft SQL Server中,WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(字符串,字符串,字符串,字符串,布尔)推荐过载我的的希望连接到一个MSSQL服务器... ...将这种需要?

Also, I see that there is an overload for WebSecurity.InitializeDatabaseConnection() with the help text: Initializes the membership system ((blah blah <snip> ProviderName: the name of the ADO.NET data provider. If you want to use Microsoft SQL Server, the WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection(String, String, String, String, Boolean) overload is recommended . I do wish to connect to a MSSQL server...will this be required?

推荐答案

该提供给你的麻烦是这是System.Data.EntityClient在连接字符串中指定的。我怀疑这个问题是因为你的项目数据库,而先简单的会员使用code-第一。我不认为你可以在一个数据库中混合使用这些方法。尝试把它回到那里DefaultConnection用于IntializeDatabaseConnection。应该有由MVC4脚手架生成你的web.config一个DefaultConnection。此连接字符串通常使用System.Data.SqlClient的作为供应商。

The provider giving you trouble is the one specified in your connection string which is System.Data.EntityClient. I suspect the problem is because your project is database-first whereas the simple membership is using code-first. I do not think you can mix these approaches in a single database. Try putting it back to where the DefaultConnection is used for IntializeDatabaseConnection. There should have been a DefaultConnection in your web.config generated by the MVC4 scaffolding. This connection string usually uses System.Data.SqlClient as the provider.

如果你想保持在用于存储域信息(即DALEntities),那么你就需要改变你的方法对域code-首先使用EF数据库中的简单成员。如果你想保持你的项目数据库,首先你需要设计自己的会员模式在数据库中,<一个href=\"http://www.asp.net/web-forms/videos/how-do-i/how-do-i-create-a-custom-membership-provider\">develop自定义成员和角色提供。这可能是最好的办法,如果你真的想要的用户信息整合到你的域模型。

If you want to keep the simple membership in the database used to store domain information (i.e. DALEntities) then you will need to change your method for using EF on the domain to code-first. If you want to keep your project database-first you need to design your own membership schema in the database and develop custom member and role providers. This is probably the best approach if you are really trying to integrate user information into your domain model.

这篇关于SimpleMembershipInitializer不会初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆