web.config' oracle.manageddataaccess.client'定义了两次

时间:2017-07-17 08:19:41

标签: c# asp.net oracle

我在ASP.NET Webforms项目上使用VS 15 Pro。我想创建一个与Oracle数据库的小型数据库连接。我安装了NuGet包' Oracle.ManagedDataAccess'。在启动项目时,它会向我抛出错误,即“oracle.manageddataaccess.client”部分' oracle.manageddataaccess.client'据说定义了两次,即使它只在web.config中定义一次。我在machine.config中找到了它,但是当我删除它时甚至无法启动VS.当我从web.config中取出它时,在使用OracleConnection.Open();时会引发错误。据推测,TNS尚未定义,但它位于tnsnames.ora中,连接字符串可用于其他项目和程序。有趣的是,使用SQL数据源ASP Web控件工作正常。

更新

它有效,现在我把TNS的定义放在连接字符串中就像这样

<connectionStrings>
  <add name="val" connectionString="Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = myHost)(PORT = 1521))(LOAD_BALANCE = yes)(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = myServiceName)));User ID=val;Password=xxxx;" providerName="System.Data.OracleClient"/>
</connectionStrings>

的web.config

<?xml version="1.0"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <section name="oracle.manageddataaccess.client"
      type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </configSections>
  <connectionStrings>
    <add name="val" connectionString="correct connection string" providerName="System.Data.OracleClient"/>
  </connectionStrings>
  <system.web>
    <authentication mode="Windows"/>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime/>
    <pages controlRenderingCompatibilityVersion="4.0"/>
  </system.web>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
  <system.data>
    <DbProviderFactories>
      <remove invariant="Oracle.ManagedDataAccess.Client"/>
      <add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <publisherPolicy apply="no"/>
        <assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <oracle.manageddataaccess.client>
    <version number="*">
      <dataSources>
        <dataSource alias="SampleDataSource" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=ORCL))) "/>
      </dataSources>
    </version>
  </oracle.manageddataaccess.client>
</configuration>

OracleConnection.Open()错误

Serverfehler in der Anwendung /.

ORA-12154: TNS: Angegebener Connect Identifier konnte nicht aufgelöst werden 
  Beschreibung: Unbehandelte Ausnahme beim Ausführen der aktuellen Webanforderung. Überprüfen Sie die Stapelüberwachung, um weitere Informationen über diesen Fehler anzuzeigen und festzustellen, wo der Fehler im Code verursacht wurde. 

 Ausnahmedetails: OracleInternal.Network.NetworkException: ORA-12154: TNS: Angegebener Connect Identifier konnte nicht aufgelöst werden

Quellfehler: 



Zeile 111:                using (OracleConnection oc = new OracleConnection(ConfigurationManager.ConnectionStrings["val"].ConnectionString))
Zeile 112:                {
Zeile 113:                    oc.Open();
Zeile 114:
Zeile 115:                    OracleCommand cmd = new OracleCommand(string.Format("select berechtigung from dim_sql_ausgeben_user where name = '{0}'", user), oc);


 Quelldatei:  C:\Users\Mschloesser\Documents\Visual Studio 2015\Projects\plain_sql_executer\plain_sql_executer\default.aspx.cs    Zeile:  113 

Stapelüberwachung: 



[NetworkException (0x2f7a): ORA-12154: TNS: Angegebener Connect Identifier konnte nicht aufgelöst werden]
   OracleInternal.Network.AddressResolution..ctor(String TNSAlias, String instanceName) +126
   OracleInternal.Network.OracleCommunication.DoConnect(String tnsDescriptor) +68
   OracleInternal.Network.OracleCommunication.Connect(String tnsDescriptor, Boolean doNAHandshake, String IName) +29
   OracleInternal.ServiceObjects.OracleConnectionImpl.Connect(ConnectionString cs, Boolean bOpenEndUserSession, CriteriaCtx criteriaCtx, String instanceName) +4760

[OracleException (0x80004005): ORA-12154: TNS: Angegebener Connect Identifier konnte nicht aufgelöst werden]
   OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, CriteriaCtx criteriaCtx, String affinityInstanceName, Boolean bForceMatch) +10583
   OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, CriteriaCtx criteriaCtx, String affinityInstanceName, Boolean bForceMatch) +951
   OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword, CriteriaCtx criteriaCtx) +1024
   Oracle.ManagedDataAccess.Client.OracleConnection.Open() +3273
   plain_sql_executer._default.check_authority() in C:\Users\Mschloesser\Documents\Visual Studio 2015\Projects\plain_sql_executer\plain_sql_executer\default.aspx.cs:113
   plain_sql_executer._default.Page_Load(Object sender, EventArgs e) in C:\Users\Mschloesser\Documents\Visual Studio 2015\Projects\plain_sql_executer\plain_sql_executer\default.aspx.cs:17
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
   System.Web.UI.Control.OnLoad(EventArgs e) +95
   System.Web.UI.Control.LoadRecursive() +59
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678

0 个答案:

没有答案