2

I am a newbie. I am using SimpleMembership to generate the Register and login tables. However, I am getting the following exception.

EXCEPTION

An exception of type 'System.ArgumentException' occurred in System.Data.dll but was not handled in user code

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

enter image description here

CODE

    [AllowAnonymous]
    [HttpGet]
    public ActionResult Register1()
    {
        if (!WebSecurity.Initialized)
        {


            //WebSecurity.InitializeDatabaseConnection("My_Entities", "Users", "Id", "UserName", autoCreateTables: true);
            WebSecurity.InitializeDatabaseConnection("My_Entities", "User", "Id", "Email", autoCreateTables: true);
        }
        return View("Register");
    }
    [AllowAnonymous]
    [HttpPost]
    public ActionResult Register1(FormCollection form)
    {
        WebSecurity.CreateUserAndAccount(form["username"], form["password"], new { DisplayName = form["displayname"], Country = form["country"] });
        Response.Redirect("~/account/login");
        return View();
    }

WEB.CONFIG

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>

  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
    <authentication mode="Forms">
      <forms loginUrl="~/Account/Login" timeout="2880" />
    </authentication>
    <membership defaultProvider="p1">
      <providers>
        <add name="p1" type="WebMatrix.WebData.SimpleMembershipProvider, WebMatrix.WebData" />
      </providers>
    </membership>
    <roleManager enabled="true">
      <providers>
        <add name="p1" type="WebMatrix.WebData.SimpleRoleProvider, WebMatrix.WebData" />
      </providers>
    </roleManager>
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
  </system.web>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false" />
    <handlers>
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <remove name="OPTIONSVerbHandler" />
      <remove name="TRACEVerbHandler" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <connectionStrings>
    <add name="MY_Entities" connectionString="metadata=res://*/Models.DB.csdl|res://*/Models.DB.ssdl|res://*/Models.DB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=MYCOMP\MYCOM;initial catalog=MY;persist security info=True;user id=sa;password=1*34;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="System.Data.SqlServerCe.4.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
  </entityFramework>
</configuration>
Julian
  • 33,915
  • 22
  • 119
  • 174
Illep
  • 16,375
  • 46
  • 171
  • 302
  • Look at here http://stackoverflow.com/questions/21797823/simple-membership-gives-me-unable-to-find-the-requested-net-framework-data-prov#answer-21804341 – Ankush Jain Dec 09 '16 at 06:21
  • Yes I did. But I didn't understand the solution. If you can elaborate a bit. – Illep Dec 09 '16 at 06:34
  • You need to have proper SQL Server (and Entity Framework) connection string(s) in `web.config` file when using `SimpleMembershipProvider`. Check if corresponding data provider had installed properly. – Tetsuya Yamamoto Dec 09 '16 at 07:11
  • I have added my `WEB.CONFIG` file in the post. Can someone tell me what should I add. Sorry, I am a newbie. – Illep Dec 09 '16 at 08:21
  • Seems that you've missing SQL Server connection string in `` element. You need to add connection string like `` at same place with EF connection string. – Tetsuya Yamamoto Dec 09 '16 at 08:30
  • It's still the same. I have the same exception as before. – Illep Dec 09 '16 at 08:35
  • Find `machine.config` file and try removing self terminating element `` if exists. Probably you have problem with database provider factory instead of missing connection string. – Tetsuya Yamamoto Dec 09 '16 at 08:39
  • I think I had a problem with the connection String. If you can add that as an answer, I can then accept it. Thanks a lot. – Illep Dec 09 '16 at 08:57
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/130194/discussion-between-tetsuya-yamamoto-and-illep). – Tetsuya Yamamoto Dec 09 '16 at 09:18

2 Answers2

0

Please try add the following configure settings in your web.config.

<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.1, Culture=neutral, PublicKeyToken=89845dcd8080cc91" />
</DbProviderFactories>

Jiancheng
  • 13
  • 7
0

The provided web.config file gives presence of System.Data.SqlServerCe.4.0 as Entity Framework's data provider on this part:

<entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlCeConnectionFactory, EntityFramework">
        <parameters>
            <parameter value="System.Data.SqlServerCe.4.0" />
        </parameters>
    </defaultConnectionFactory>
    <providers>
        <provider invariantName="System.Data.SqlServerCe.4.0" type="System.Data.Entity.SqlServerCompact.SqlCeProviderServices, EntityFramework.SqlServerCompact" />
    </providers>
</entityFramework>

Since the error clearly said that the requested data provider is not yet installed, find out machine.config file in %Windows%\Microsoft.NET\Framework\[version number]\Config, edit it in admin privileges then add these lines below (or if you're being lazy to dig up machine.config, place them into web.config under system.data element):

<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>

Also, remove any single-terminating element of <DbProviderFactories /> if you found them.

Next, you may adding references related to SQL Server CE (sqlce*.dll) using Package Manager Console by finding EntityFramework.SqlServerCompact package (refer this one) and install it on your solution. Additionally, change provider name System.Data.SqlClient to System.Data.SqlServerCe.4.0 in EF (and SQL Server) connection string when required.

References:

Unable to find the requested .Net Framework Data Provider

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

Unable to find the requested .Net Framework Data Provider. It may not be installed. - when following mvc3 asp.net tutorial

Community
  • 1
  • 1
Tetsuya Yamamoto
  • 24,297
  • 8
  • 39
  • 61