ASP.NET IIS 7 中带有 EF 6.1.3 的应用

ASP.NET app with EF 6.1.3 in IIS 7

我们刚刚设置了一个新的 PCI 兼容服务器,当我将我的 asp.net 应用程序部署到它时,我收到此错误消息:

具有不变名称 'System.Data.SqlClient' 的 ADO.NET 提供程序未在计算机或应用程序配置文件中注册,或者无法加载。有关详细信息,请参阅内部异常。

我仔细检查了我的配置文件,卸载了 EF 并在所有项目中重新安装了它。部署后我在 bin 文件夹中看到了 DLL(我们对 team city 和 octopus 使用 CI)。我在线检查了几乎所有 post 的解决方案,但都没有成功。

当我将此应用程序部署到不符合 PCI 的服务器时,它工作正常。我不知道是什么原因造成的!!

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>

** 异常 **

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)

任何人 运行 通过这个,终于弄明白了。
在 machine.config 文件中:

32 位

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

64 位

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

定义了一个 dbproviders 部分,但紧随其后的是另一个这样定义的部分 <DbProviderFactories/>

删除第二个应用程序后,该应用程序便开始运行,并且上述错误不再出现。
问题仍然是为什么机器配置会定义两个部分。没有人手动编辑此文件!!