System.Configuration.ConfigurationErrorsException发生错误创建上下文' spring.root' - InnerException:Client.OracleException

时间:2015-06-03 19:28:52

标签: c# spring oracle nhibernate

目前,我正在尝试调试连接到oracle数据库的Web应用程序。当我运行该应用程序时,我收到以下错误:

System.Configuration.ConfigurationErrorsException occurred
  HResult=-2146232062
  Message=Error creating context 'spring.root': 
  Source=System.Configuration
  BareMessage=Error creating context 'spring.root': 
  Line=0
  StackTrace:
     at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)
     at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)
     at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
     at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
     at System.Web.HttpContext.GetSection(String sectionName)
     at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName)
     at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey)
     at System.Configuration.ConfigurationManager.GetSection(String sectionName)
     at Spring.Util.ConfigurationUtils.GetSection(String sectionName)
     at Spring.Context.Support.ContextRegistry.InitializeContextIfNeeded()
     at Spring.Context.Support.ContextRegistry.GetContext()
     at Middleware.Data.Services.ServiceFactory.get_WellService() in C:\Dev\trunk\Middleware\Data\Services\ServiceFactory.cs:line 25
InnerException: Spring.Objects.Factory.ObjectCreationException
     HResult=-2146232832
     Message=Error creating object with name 'NHibernateSessionFactory' defined in 'assembly [Middleware.Data.DomainRepository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c61376b85e43767], resource [Middleware.Data.DomainRepository.Persistence.xml] line 15' : Initialization of object failed : 
     Source=Spring.Core
     ObjectName=NHibernateSessionFactory
     ResourceDescription=assembly [Middleware.Data.DomainRepository, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5c61376b85e43767], resource [Middleware.Data.DomainRepository.Persistence.xml] line 15
     StackTrace:
          at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure)
          at Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments)
          at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure)
          at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name)
          at Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects)
          at Spring.Objects.Factory.ObjectFactoryUtils.ObjectsOfTypeIncludingAncestors(IListableObjectFactory factory, Type type, Boolean includePrototypes, Boolean includeFactoryObjects)
          at Spring.Dao.Support.PersistenceExceptionTranslationInterceptor.DetectPersistenceExceptionTranslators(IListableObjectFactory objectFactory)
          at Spring.Dao.Support.PersistenceExceptionTranslationInterceptor..ctor(IListableObjectFactory objectFactory)
          at Spring.Dao.Attributes.PersistenceExceptionTranslationAdvisor..ctor(IListableObjectFactory objectFactory, Type repositoryAttributeType)
          at Spring.Dao.Attributes.PersistenceExceptionTranslationPostProcessor.set_ObjectFactory(IObjectFactory value)
          at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper)
          at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure)
          at Spring.Objects.Factory.Support.AbstractObjectFactory.CreateAndCacheSingletonInstance(String objectName, RootObjectDefinition objectDefinition, Object[] arguments)
          at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObjectInternal(String name, Type requiredType, Object[] arguments, Boolean suppressConfigure)
          at Spring.Objects.Factory.Support.AbstractObjectFactory.GetObject(String name)
          at Spring.Objects.Factory.Support.DefaultListableObjectFactory.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects)
          at Spring.Context.Support.AbstractApplicationContext.GetObjectsOfType(Type type, Boolean includePrototypes, Boolean includeFactoryObjects)
          at Spring.Context.Support.AbstractApplicationContext.RegisterObjectPostProcessors(IConfigurableListableObjectFactory objectFactory)
          at Spring.Context.Support.AbstractApplicationContext.Refresh()
          at Spring.Context.Support.XmlApplicationContext..ctor(XmlApplicationContextArgs args)
          at Spring.Context.Support.XmlApplicationContext..ctor(String name, Boolean caseSensitive, String[] configurationLocations)
          at _dynamic_Spring.Context.Support.XmlApplicationContext..ctor(Object[] )
          at Spring.Reflection.Dynamic.SafeConstructor.Invoke(Object[] arguments)
          at Spring.Context.Support.ContextHandler.RootContextInstantiator.InvokeContextConstructor(ConstructorInfo ctor)
          at Spring.Context.Support.ContextHandler.ContextInstantiator.InstantiateContext()
          at Spring.Context.Support.ContextHandler.InstantiateContext(IApplicationContext parentContext, Object configContext, String contextName, Type contextType, Boolean caseSensitive, String[] resources)
          at Spring.Context.Support.ContextHandler.Create(Object parent, Object configContext, XmlNode section)
     InnerException: Oracle.DataAccess.Client.OracleException
          HResult=-2147467259
          Message=""
          ErrorCode=-2147467259
          StackTrace:
               at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck, Int32 isRecoverable)
               at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, Object src)
               at Oracle.DataAccess.Client.OracleConnection.Open()
               at Spring.Data.NHibernate.LocalSessionFactoryObject.DbProviderWrapper.GetConnection()
               at NHibernate.Tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.Prepare()
               at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.GetReservedWords(Dialect dialect, IConnectionHelper connectionHelper)
               at NHibernate.Tool.hbm2ddl.SchemaMetadataUpdater.Update(ISessionFactory sessionFactory)
               at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg, IMapping mapping, Settings settings, EventListeners listeners)
               at NHibernate.Cfg.Configuration.BuildSessionFactory()
               at Spring.Data.NHibernate.LocalSessionFactoryObject.NewSessionFactory(Configuration config)
               at Spring.Data.NHibernate.LocalSessionFactoryObject.AfterPropertiesSet()
               at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InvokeInitMethods(Object target, String name, IConfigurableObjectDefinition definition)
               at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.ConfigureObject(String name, RootObjectDefinition definition, IObjectWrapper wrapper)
               at Spring.Objects.Factory.Support.AbstractAutowireCapableObjectFactory.InstantiateObject(String name, RootObjectDefinition definition, Object[] arguments, Boolean allowEagerCaching, Boolean suppressConfigure)
          InnerException: 

从查看最里面的内部异常,看起来我的应用程序很难连接到Oracle。这是我的连接字符串,我手动验证使用sqlplus正常工作。

  <add name="MyApp"
   connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SID=orcl)));User Id=myID;Password=myPassword;"
   providerName="OracleODP-11-2.0" />

<add name="BlenderConnection"
    connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SID=orcl)));User Id=ppdID;Password=ppdPassword;"
    providerName="Oracle.ManagedDataAccess.Client"/>

<add name="Oracle"
     connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVER=DEDICATED)(SID=orcl)));User Id=myID;Password=myPassword;"
     providerName="Oracle.ManagedDataAccess.Client"/>

有没有人有任何建议? TIA。

1 个答案:

答案 0 :(得分:0)

我停止获取上述异常的方法是卸载TeamCity并从IIS管理器中删除我的应用程序的网站。

要说清楚,我认为问题不在于TeamCity - 问题在于我运行了一个构建来部署我的应用程序,它将网站添加到IIS并导致某种冲突导致我的错误我试图调试我的网站时的问题。

此外,问题的一部分是我收到了这个例外:

Exception Details: System.BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.

BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.]

[BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess, Version=2.112.3.0, Culture=neutral, PublicKeyToken=89b483f429c47342' or one of its dependencies. An attempt was made to load a program with an incorrect format.]
   System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks) +0

为了解决上述问题,我安装了32位客户端,但错误地为oracle 12安装了一个,实际上我需要Oracle 11g 32位客户端:

ODAC121021Xcopy_32bit.zip

要解决此问题,我卸载了上述内容,并确保从C:\ Windows \ assembly明确卸载所有Oracle.DataAccess.dll 2.121项目。然后我安装了正确的Oracle 11g 32位客户端:

 ODTwithODAC1120320_32bit.zip

接下来,我更新了这个文件并运行它:

C:\app\oracle\product\11.2.0\dbhome_1\bin\selecthome.bat

然后我打开了这个文件:

C:\oracle\configure.bat

要确保它正确地将2.121.2.0的所有值更改为2.112.3,并运行如下文件:

C:\oracle>configure.bat all ORACLE_HOME true

执行此文件后,在C:\ Windows \ Microsoft.NET \ Framework \ v2.0.50727 \ CONFIG \ machine.config等位置找到的所有machine.config文件都应具有Oracle.DataAccess集的版本号正常。

但是,我强烈建议您使用已经发布的托管.NET客户端,而不是搞乱上述内容,如果可以的话:

http://www.oracle.com/technetwork/topics/dotnet/index-085163.html

不幸的是,现在我必须与非托管客户端合作。