MVC4 - 会员 - 的SQL Server Compact 4.0 - 例外:无法找到所请求的.NET Framework数据提供 [英] MVC4 - Membership - SQL Server Compact 4.0 - Exception: Unable to find the requested .Net Framework Data Provider

查看:180
本文介绍了MVC4 - 会员 - 的SQL Server Compact 4.0 - 例外:无法找到所请求的.NET Framework数据提供的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

InitializeDatabaseConnection方法文档 说,我们可以用SQLCE使用MVC 4互联网模板的成员生成功能(SQL Server精简4.0本地数据库)。

The InitializeDatabaseConnection Method documentation says we can use the MVC 4 "Internet" template's generated membership functionality with SQLCE (SQL Server Compact 4.0 Local Database).

我用这个模板很多次和从未有过一个问题,当我没有任何东西乱动,只是使用的是由实体框架是我们第一次注册一个用户生成的LocalDB(默认值)。

I've used this template many times before and have never had a problem when I didn't fiddle with anything and simply used the localDb (the default) that is generated by the Entity Framework the first time we register a user.

我的要求是获得由产生踏入2012年的LocalDB数据库,而不是生成到一个SQLCE数据库的默认成员表。不过,我得到以下几点:

My requirement is to get the membership tables that are by default generated into 2012 localDb database instead to generate into a SQLCE database. However, I'm getting the following:

例外:无法找到所请求的.NET Framework数据提供程序。它可能没有安装。

Exception: Unable to find the requested .Net Framework Data Provider. It may not be installed.

要做到这一点,我们简单:

To do this we simply:


  1. 打开Visual Studio(如preSS正常工作)。

  2. 生成一个新的 MVC4 - >网络(含账户)项目

  3. 一个SQLCE数据库添加到〜/ App_Data文件/ 文件夹(右键单击该文件夹并选择添加 - >的SQL Server Compact 4.0本地数据库)。

  4. 添加表则记录表。

  5. 右键单击 模式文件夹并选择的添加 - > ADO.NET实体数据模型

  6. 打开(根)web.config文件,并复制的ConnectionString的名字(<添加名称=ceEntities

  7. 找到code的下面一行〜/过滤器/ InitializeSimpleMembershipAttribute 类: WebSecurity.InitializeDatabaseConnection(ceEntities,用户配置,用户ID,用户名,autoCreateTables:TRUE);

  8. F5编译/运行/调试项目

  9. 一旦家庭/索引页面加载点击注册链接在右上角

  10. 输入用户名和密码进行注册,然后单击确定。

  1. Open Visual Studio (express works fine).
  2. Generate a new MVC4 --> Internet (with account) project.
  3. Add a SQLCE database to the ~/App_Data/ folder (right-click the folder and select Add --> SQL Server Compact 4.0 Local Database).
  4. Add table then a record to the table.
  5. Right-click the Models folder and select Add --> ADO.NET Entity Data Model
  6. Open the (root) web.config and copy the name of the 'connectionstring'(<add name="ceEntities")
  7. Locate the following line of code in the ~/Filters/InitializeSimpleMembershipAttribute class: WebSecurity.InitializeDatabaseConnection("ceEntities", "UserProfile", "UserId", "UserName", autoCreateTables: true);
  8. F5 to compile/run/debug the project
  9. Once the home/index page loads click the "Register" link in the upper right hand corner
  10. Enter a username and password to register and click 'Ok.'

到现在为止的code编译并运行良好但是当code的下面一行〜/过滤器/ InitializeSimpleMembershipAttribute 类运行:

Up to this point the code compiles and runs fine however when the following line of code is run in the ~/Filters/InitializeSimpleMembershipAttribute class:

WebSecurity.InitializeDatabaseConnection("ceEntities", "UserProfile", "UserId", "UserName", autoCreateTables: true);

这捕获异常:
无法找到所请求的.NET Framework数据提供程序。它可能没有安装。

This exception is caught: Unable to find the requested .Net Framework Data Provider. It may not be installed.

这显然是固定的,当我们的添加此code到web.config

Which is apparently fixed when we add this code to the web.config:

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SqlServerCe.4.0" />
      <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
    </DbProviderFactories>
  </system.data>

而当我们再次运行下面的异常被捕获:

And when we run it again the following exception is caught:

无法找到所需的.NET Framework数据提供程序。它可能没有安装。

Unable to find the requested .Net Framework Data Provider. It may not be installed.

推荐答案

感谢您斯科特Hanselman的和谁使他意识到与SQLCE协议的成员资格提供在他的 Introducing System.Web.Providers - 会话,成员,角色和用户配置文件的SQL精简和SQL Azure的博客文章ASP.NET通用提供商 斯科特概述以实现ASP.NET的步骤通用供应商。这帮助我,因为他概述了SQLCE正确的连接字符串概要:

Thank you to Scott Hanselman and whoever made him aware of the Membership Provider with SQLCE protocol as in his Introducing System.Web.Providers - ASP.NET Universal Providers for Session, Membership, Roles and User Profile on SQL Compact and SQL Azure blog post Scott outlines the steps to implement the ASP.NET Universal Providers. This helped me as he outlined the proper connection string outline for SQLCE:

<connectionstrings>
   <add name="Sql_CE" 
        connectionstring="Data Source=|DataDirectory|\MyWebSite.sdf;" 
        providername="System.Data.SqlServerCe.4.0">
   </add>
</connectionstrings>

所以我我的ConnectionString更新为:

So I updated my connectionstring to:

<connectionstrings>
   <add name="defaultconnection" 
        connectionstring="Data Source=|DataDirectory|\ce.sdf;" 
        providername="System.Data.SqlServerCe.4.0">
   </add>
</connectionstrings>

然后更新的connectionStringName 〜/过滤器/ InitializeSimpleMembershipAttribute 类回:

WebSecurity.InitializeDatabaseConnection("defaultconnection", "UserProfile", "UserId", "UserName", autoCreateTables: true);

没有错误或异常编译的应用程序,所以我跑了那么应用程序注册的用户,并在这一过程中适用SimpleMembership表被生成到我的ce.sdf(SQL Server精简4.0本地数据库)。

The application compiled without an error or exception so I ran the application then Registered a user and in that process the applicable SimpleMembership tables were generated into my "ce.sdf" (SQL Server Compact 4.0 Local Database).

我现在能够利用SimpleMembership默认的在他们的最好!

I am now able to utilize the SimpleMembership default's at their fullest!

P.S,为了简便起见,我要现在编辑我的初始后/问题省略了踪迹,只留下了异常。

p.s., For brevity I'm going to now edit my initial post/question to omit the stacktraces, leaving only the exceptions.

这篇关于MVC4 - 会员 - 的SQL Server Compact 4.0 - 例外:无法找到所请求的.NET Framework数据提供的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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