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

Gary O. Stenstrom picture Gary O. Stenstrom · Jan 22, 2013 · Viewed 11k times · Source

I know that there have been a lot of other postings on this error but none have been able to shed any light or help on my issue. I am using a straight up connection to SqlExpress, so no special Oracle or MySQL databases or anything. It seems like this should just fit like a glove.

So the scenario is this, I have created a solution, comprised of a handful of projects; Repositories, Data (EF5.0), Utilities, a Test project and an MVC Web Application. The goal is to simply access an underlying SQL Express database via the Data classes via repositories in the Repositories project using EF5 and some repositories from the test project and the MVC Application.

The test project works and is able to access and update the database with no issue.

The MVC Web Project, however, is throwing the "Unable to find the requested .Net Framework Data Provider. It may not be installed." error, which I do not understand as it uses the same connection string as the Test Project.

[ArgumentException: Unable to find the requested .Net Framework Data Provider.  It may not be installed.]
   System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName) +1426271
   WebMatrix.Data.DbProviderFactoryWrapper.CreateConnection(String connectionString) +64
   WebMatrix.Data.<>c__DisplayClass15.<OpenConnectionStringInternal>b__14() +16
   WebMatrix.Data.Database.get_Connection() +19
   WebMatrix.Data.Database.EnsureConnectionOpen() +12
   WebMatrix.Data.Database.QueryValue(String commandText, Object[] args) +63
   WebMatrix.WebData.DatabaseWrapper.QueryValue(String commandText, Object[] parameters) +14
   WebMatrix.WebData.SimpleMembershipProvider.GetUserId(IDatabase db, String userTableName, String userNameColumn, String userIdColumn, String userName) +232
   WebMatrix.WebData.SimpleMembershipProvider.ValidateUserTable() +85

I have ...

  1. Registered the System.Data.SqlClient in the web.config.
  2. Verified that the registered version (2.0.0.0) of System.Data exists in the GAC per this article
  3. Made sure that there were no typos in the Connection String.

Here's what I have in the web.config ...

  <connectionStrings>
    <add name="DBCatalogContext" 
         connectionString="metadata=res://*/DBCatalog.csdl|
                                    res://*/DBCatalog.ssdl|
                                    res://*/DBCatalog.msl;
                                    provider=System.Data.SqlClient;
                                    provider connection string=&quot;data source=.\SQLEXPRESS;
                                                                     initial catalog=DBCatalog;
                                                                     integrated security=True;
                                                                     multipleactiveresultsets=True;
                                                                     App=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
  </connectionStrings>

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

The only thing I see that doesn't make sense to me is, when I select the "System.Data" reference under the "References" folder and look at the properties it says that it's version 4.0.0.0, but when I change the version in the "DbProviderFactories" section of the config site I still get the error. Also I don't even see the reference to this library in the Test project which works.

I am confident that this is an oversight or that I am missing some config setting, but I do not know where else to look at this point, so any help would be appreciated.

Thanks, G

Answer

Gary O. Stenstrom picture Gary O. Stenstrom · Jan 23, 2013

I had apparently left out some ultimately pertinent information when I originally posted. This included the fact that the error was being thrown by the membership services; specifically the ... SimpleMembershipInitializer ... originally this class specified the connection string ... "DefaultConnection" defined in the web.config, to be used when initializing the database connection.

WebSecurity.InitializeDatabaseConnection("DefaultConnection", "Users", "UserId", "UserName", autoCreateTables: false);

I had changed it to use the "DBCatalogContext" connection string I had added to the web.config, thinking that I would use this single connection string instead. The problem, of course, is that the new connection string that I added was an Entity Framework connection string which the membership services did not recognize resulting in the data provider error.

I simply added back the original, regular connection string, in addition to the Entity Framework connection string and now everything works. Well everything relating to this issue ...

<connectionStrings>
    <add name="DBCatalogContext" 
         connectionString="metadata=res://*/DBCatalog.csdl|
                                    res://*/DBCatalog.ssdl|
                                    res://*/DBCatalog.msl;
                                    provider=System.Data.SqlClient;
                                    provider connection string=&quot;data source=.\SQLEXPRESS;
                                                                     initial catalog=DBCatalog;
                                                                     integrated security=True;
                                                                     multipleactiveresultsets=True;
                                                                     App=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />


    <add name="DefaultConnection" 
         providerName="System.Data.SqlClient" 
         connectionString="data source=.\SQLEXPRESS;initial catalog=DBCatalog;integrated security=True;multipleactiveresultsets=True;App=EntityFramework" />

  </connectionStrings>

I hope that someone else can find this helpful.