我们刚刚设置了一个新的PCI兼容服务器,当我部署我的asp.net应用程序时,我收到此错误消息:
ADO.NET提供程序具有不变名称' System.Data.SqlClient'要么未在计算机或应用程序配置文件中注册,要么无法加载。有关详细信息,请参阅内部异常。
我仔细检查了我的配置文件,卸载了EF并在所有项目中重新安装了它。我在部署后看到bin文件夹中的DLL(我们使用带有团队城市和章鱼的CI)。我在线检查了几乎所有的帖子,找不到成功的解决方案。
当我将此应用程序部署到非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>
&#13;
**例外**
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)
&#13;
答案 0 :(得分:2)
对于任何经历过此事的人来说,终于弄明白了 在machine.config文件中:
32位
%windir%\Microsoft.NET\Framework\[version]\config\machine.config
<强> 64位强>
%windir%\Microsoft.NET\Framework64\[version]\config\machine.config
定义了一个dbproviders部分,但在它之后还有另一个定义为<DbProviderFactories/>
只要第二个被删除,应用程序就会开始工作,上面的错误就会停止显示 问题仍然是为什么机器配置会定义两个部分。没有人手动编辑这个文件!!