Unable to find the requested .Net Framework Data P

2019-06-17 06:36发布

I am trying to set up a simple ASP.NET MVC 4 webapp using DB first migrations from a SQL Server (2005). I have created the tables in the database and used Entity Framework to create the objects in the code. I can access the data using these objects.

The problems come when I try to initialize the WebSecurity using WebSecurity.InitializeDatabaseConnection("FLMREntities", "UserProfile", "UserId", "UserName", true); in the Global.asax.cs file. I have tried using the InitializeSimpleMembershipAttribute filter that came with the template and got the same issue. I get the error message:

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

Here is the relevant connection string:

<add name="FLMREntities"
     connectionString="metadata=res://*/Models.FLMR.csdl|res://*/Models.FLMR.ssdl|res://*/Models.FLMR.msl;
                    provider=System.Data.SqlClient;
                    provider connection string=&quot;data source=notes.marietta.edu;
                        initial catalog=muskwater;
                        user id=muskwater;password=********;
                        MultipleActiveResultSets=True;
                        App=EntityFramework&quot;" 
     providerName="System.Data.EntityClient" />

Also, I have created the membership tables in the database to match what the template creates. If I change the final parameter in the Initialize call to false (so that it does not try to create the tables automatically) it returns that it cannot find the UserProfile table. I have also tried variations on the names, such as [dbo].[UserProfile].

All I need is to have a simple account model to allow users to log in and allow certain users to see more content.

3条回答
贪生不怕死
2楼-- · 2019-06-17 06:48

I had a similar problem, what I've done: I modified the default connection. I already had a connection string for the edmx model, which looked like this:

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

But I cannot used it with the SimpleMemebrship provider. So in Visual Studio I opened the Server Explorer > Data Connections, I selected my connection, right click, properties and I copied the connection string from there and pasted it to defaultConnection:

<add name="DefaultConnection" connectionString="Data Source=.\SQLExpress;Initial Catalog=ChemicalReporter;Integrated Security=True;MultipleActiveResultSets=True;Application Name=EntityFramework" providerName="System.Data.SqlClient" />

After that I changed WebSecurity.InitializeDatabaseConnection to use the DefaultConnection.

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "UserProfile", "UserId", "UserName", true);
查看更多
等我变得足够好
3楼-- · 2019-06-17 06:50

Just wanted to chime in here, that I had this issue, by looking at my machine.config for the targeted .NET version that I was running off of... within the structure:

ensure that your targeted data providers are correctly inputted within there, only one per provider (I have seen duplicates cause problems), as well as, ensure that it is valid XML, and you only have one DBProviderFactories entry. In my case, I had a entry after the initial entry (essentially two entries, one with my providers, one blank), and the blank was was causing all the issues.

Hope this helps someone with the same issue :)

查看更多
孤傲高冷的网名
4楼-- · 2019-06-17 06:56

This could be a duplicate of this.

From what I remember about this problem, you need to make sure that the sqldata provider is registered. Sometimes, in your machine.config there is a duplicate entry that you need to delete and if I remember correctly, there could be an erroneous entry that you need to remove. Have a look at this msdn post, the info for this is about halfway down the page.

The link to the other SO has some links that could be helpful. If this ends up not being marked as a duplicate question, I can add them here as well or whatever is the proper thing to do.

The section you are looking for will look similar to this I think:

<system.data>
  <DbProviderFactories>
    <add name="SqlClient Data Provider"
     invariant="System.Data.SqlClient" 
     description=".Net Framework Data Provider for SqlServer" 
     type="System.Data.SqlClient.SqlClientFactory, System.Data, 
     Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
    />
  </DbProviderFactories>
</system.data>

From the information you have provided in comments, it seems that this is missing in your machine.config. Unless I am mistaken (possible) that means that the SQL Provider isn't registered on your machine. You'll need to add the above section to your web.config. You'll also need to make sure that System.Data.SqlClient is referenced in your project.

If this isn't installed on your target machine, you'll have more work to do, getting it installed. I wish I could help you with that more, but when I did this, it was for SqlServerCE, so the files I used are much different.

Good luck!

EDIT: A critical piece of information, is the version needs to match the file that you are using. in type="blabh..blah..blah..Version=2.0.0.0, blah blah" that needs to be the version of the file you are using so right click your file and get the file version. If it fails, try variations of the version. I believe my file was 2.0.0.1 but Version=2.0 is what worked when I did it. Just try a few different versions based on your version number (2.0, 2.0.0, 2.0.0.1 for example).

查看更多
登录 后发表回答