-1

We just setup a new PCI compliant server and when I deploy my asp.net app to it I get this errors message:

The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.

I double checked my config file, uninstalled EF and reinstalled it in all the projects. I see the DLL in the bin folder after deployment (we use CI with team city and octopus). I checked almost all the post online for solutions to no success.

When I deploy this app to a non PCI compliant server it works fine. I'm out of ideas to what can cause it!!

web.config

<configSections>
  <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false"/>
    </configSections>

<!-- Connection String -->
<add name="BondedBuilderModel" connectionString="data source=SqlServer;initial catalog=mydb;integrated security=false;User Id=user; Password =pass;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient"/>
     

<!-- Provider -->
    <entityFramework>
        <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework">
            <parameters>
                <parameter value="System.Data.SqlClient"/>
            </parameters>
        </defaultConnectionFactory>
        <providers>
            <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer"/>
        </providers>
    </entityFramework>

** Exception **

The ADO.NET provider with invariant name 'System.Data.SqlClient' is either not registered in the machine or application config file, or could not be loaded. See the inner exception for details.
  at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.<GetService>b__0(ArgumentException e, String n)
  at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key, Func`3 handleFailedLookup)
  at System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key)
  at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple`2 k)
  at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
  at System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.GetService(Type type, Object key)
  at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
  at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
  at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
  at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
  at System.Data.Entity.Infrastructure.DependencyResolution.RootDependencyResolver.GetService(Type type, Object key)
  at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
  at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
  at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
  at System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
  at System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver`2.GetService(Type type, Object key)
  at System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
  at System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName(String providerInvariantName)
  at System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
  at System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config)
  at System.Data.Entity.Internal.LazyInternalConnection.Initialize()
  at System.Data.Entity.Internal.LazyInternalConnection.get_ProviderName()
  at System.Data.Entity.Internal.LazyInternalContext.get_ProviderName()
  at System.Data.Entity.Internal.DefaultModelCacheKeyFactory.Create(DbContext context)
  at System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
  at System.Data.Entity.Internal.InternalContext.GetEntitySetAndBaseTypeForType(Type entityType)
  at System.Data.Entity.Internal.Linq.InternalSet`1.Initialize()
  at System.Data.Entity.Internal.Linq.InternalSet`1.get_InternalContext()
  at System.Data.Entity.Internal.Linq.InternalSet`1.ActOnSet(Action action, EntityState newState, Object entity, String methodName)
  at System.Data.Entity.Internal.Linq.InternalSet`1.Add(Object entity)
  at System.Data.Entity.DbSet`1.Add(TEntity entity)
  at BondedBuilders.Data.LoggerData.LogError(String errorType, String errorMessage, String stackTrace) in c:\TeamCity\buildAgent\work\f206d6cc22a03ea8\source\web\BondedBuilders.Data\LoggerData.cs:line 31
  at BondedBuilders.Data.LoggerData.LogError(Exception exception) in c:\TeamCity\buildAgent\work\f206d6cc22a03ea8\source\web\BondedBuilders.Data\LoggerData.cs:line 11
  at BondedBuilders.WebClient.Templates.Main.HandleSystemError(Exception ex) in c:\TeamCity\buildAgent\work\f206d6cc22a03ea8\source\web\BondedBuilders.WebClient\Templates\Main.Master.cs:line 18
  at BondedBuilders.WebClient.Default.ButtonContinue_Click(Object sender, EventArgs e) in c:\TeamCity\buildAgent\work\f206d6cc22a03ea8\source\web\BondedBuilders.WebClient\Default.aspx.cs:line 95
  at System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e)
  at System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument)
  at System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
  at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
  at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
  at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
mghz
  • 377
  • 1
  • 12
  • "See the inner exception for details." What does the inner exception say? – Matt Rowland May 06 '16 at 16:28
  • Possible duplicate of [Entity Framework ADO.NET Sql.Data.Client provider not found](http://stackoverflow.com/questions/20111583/entity-framework-ado-net-sql-data-client-provider-not-found) – Matt Rowland May 06 '16 at 17:00
  • I tried all the suggestions on that post and nothing worked. as you notice from the comments that issue was not resolved either. – mghz May 06 '16 at 17:06
  • Again, can you add more information to your question. The inner exception? The config file? 3rd time this has been mentioned. – Matt Rowland May 06 '16 at 17:07
  • added the config and error – mghz May 06 '16 at 17:29
  • What is the inner exception? You already posted the initial error, no need to be redundant. – Matt Rowland May 06 '16 at 17:37
  • Try [bypassing the machine.config](http://stackoverflow.com/a/2201249/6268935). Does it work? – Arman Peiravi May 06 '16 at 17:39
  • I tried that got a different error now: "The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception" ... it did not like the clear on the provider. Removed it from the provider and kept it on the conn string ... same error – mghz May 06 '16 at 18:47
  • The duplicate question Matt linked to, it shows the original poster had to recreate the solution. Have you tried creating a new bare bones test solution to see if it exhibits the same behavior? You say that it works fine when deploying to non PCi servers; is it the same exact code/package you're deploying? One thing worth checking is to compare the machine.config on the PCI vs non-PCI machines and see if there's a significant difference with the DB factories. – Arman Peiravi May 06 '16 at 22:31
  • Yes it's the exact same package, i tried re-creating the solution but I don't think it's a solution or code issue as it works fine when deployed to another server that is not locked down. I think it's something on the server that is causing the issue. I will try comparing the machine config files and post again. Thanks. – mghz May 08 '16 at 15:00
  • the only difference between the config files is one of them, the server that works, has this added to it: – mghz May 09 '16 at 15:11

1 Answers1

2

For anyone running through this, finally figured it out.
In the machine.config file:

32-bit

%windir%\Microsoft.NET\Framework\[version]\config\machine.config 

64-bit

%windir%\Microsoft.NET\Framework64\[version]\config\machine.config 

There was a dbproviders section defined but right after it there was another one defined like this <DbProviderFactories/>

As soon as this second one was deleted the app started to work and the error above stopped showing up.
The question remains why would the machine config have both sections defined. No one manually edited this file!!

Gabbyboy
  • 1,984
  • 2
  • 14
  • 20
mghz
  • 377
  • 1
  • 12
  • Good find! I had a hunch the issue was in the machine.config which is why I was so fixated on it in my comments and why I recommended the compare. Glad you found it. – Arman Peiravi May 10 '16 at 02:23