【问题标题】:ORA-12154: TNS:could not resolve the connect identifier specified and ORA-06413: Connection not openORA-12154: TNS: 无法解析指定的连接标识符和 ORA-06413: 连接未打开
【发布时间】:2017-06-13 17:54:41
【问题描述】:

我已经安装了 64 位的 windows 2008 操作系统和 oracle 10g 数据库和 Visual Studio 2015。

无法连接 oracle 数据库 10g。

以及现有的开发应用程序,该应用程序是使用 Visual Studio 2010 开发的,该应用程序在带有 oracle 10g 数据库的 windows xp 上运行。

请帮帮我。

【问题讨论】:

  • 请指导我如何连接数据库。
  • 现有应用程序建立连接,然后错误显示 ORA-06413:连接未打开。并使用服务器资源管理器建立新连接--->数据连接->在测试连接错误消息中添加新连接:----------->ORA-12154:TNS:无法解析连接标识符指定。

标签: windows visual-studio-2015 oracle10g


【解决方案1】:
Can you try the below

1. Include Oracle.ManagedDataAccess.dll in your solution.
2. In web.config, Under Configuration and connectionstrings, include the below

    <oracle.manageddataaccess.client>
        <version number="*">
          <dataSources>
            <dataSource alias="UATDB" descriptor="(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = ORACLEDBIP)(PORT = PORT))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ORACLE)))"/>
        </dataSources>
        </version>
      </oracle.manageddataaccess.client>

        <connectionStrings>
        <add name="UATCONNECTIONSTRING" connectionString="Data Source=UATDB;User Id=username;Password=password;Min Pool Size=10; Connection Lifetime=300;Connection Timeout=300;Incr Pool Size=5;Decr Pool Size=2;" providerName="Oracle.DataAccess.Client"/>  
      </connectionStrings>


3. Refer the dll in your application

    using Oracle.ManagedDataAccess;

    using (OracleConnection oraConn = new OracleConnection(strOracleConn))
    {
        oraConn.Open();
        OracleCommand oraCommand = new OracleCommand();
        oraCommand.CommandType = System.Data.CommandType.StoredProcedure;
        oraCommand.CommandText = "sp name";
        oraCommand.Connection = oraConn;
    }



Web.config file

<?xml version="1.0"?>
<configuration>
  <configSections>
    <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess"/>
  </configSections>
  <oracle.manageddataaccess.client>
    <version number="*">
      <dataSources>
        <dataSource alias="UATDB" descriptor="(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = IP)(PORT = PORT))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = ORACLE)))"/>
      </dataSources>
    </version>
  </oracle.manageddataaccess.client>
  <system.web>
    <compilation debug="true" targetFramework="4.6.1"/>
    <customErrors mode="Off"/>
    <httpRuntime executionTimeout="600"/>
    <authentication mode="Windows"/>
    <authorization>
      <deny users="?"/>
    </authorization>
    <pages controlRenderingCompatibilityVersion="4.0">
      <namespaces>
        <add namespace="System.Web.Optimization"/>
      </namespaces>
      <controls>
        <add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt"/>
      </controls>
    </pages>
    <httpModules>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
    </httpModules>
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed"/>
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0"/>
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" culture="neutral" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <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>
  <connectionStrings>
    <add name="UATCONNECTIONSTRING" connectionString="Data Source=UATDB;User Id=user1;Password=pass12;Min Pool Size=10; Connection Lifetime=300;Connection Timeout=300;Incr Pool Size=5;Decr Pool Size=2;" providerName="Oracle.DataAccess.Client"/>
  </connectionStrings>
  <appSettings>
  </appSettings>
  <system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules>
      <remove name="ApplicationInsightsWebTracking"/>
      <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web" preCondition="managedHandler"/>
    </modules>
  </system.webServer>
    <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString">
        <conversionPattern value="../Logs/RunningLog/WrapperRunningLog-" />
      </file>
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMddHH.lo\g" />
      <staticLogFileName value="false" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %level - %message%newline" />
      </layout>
    </appender>
    <appender name="RollingLogFileAppenderUpdateStatus" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString">
        <conversionPattern value="../Logs/UpdateStatusLog/StatusLog-" />
      </file>
      <rollingStyle value="Date" />
      <datePattern value="yyyyMMdd.log" />
      <staticLogFileName value="false" />
      <layout type="log4net.Layout.PatternLayout">
        <conversionPattern value="%date %level - %message%newline" />
      </layout>
    </appender>
    <root>
      <level value="ALL" />
    </root>
    <logger name="RunningLog">
      <level value="ALL" />
      <appender-ref ref="RollingLogFileAppender"   />
    </logger>
    <logger name="UpdateStatusLog">
      <level value="ALL" />
      <appender-ref ref="RollingLogFileAppenderUpdateStatus" />
      <appender-ref ref="RollingLogFileAppender"   />
    </logger>
  </log4net>
</configuration>

【讨论】:

  • Oracle.ManagedDataAccess.dll 中出现“System.ArgumentException”类型的异常,但未在用户代码中处理其他信息:“Provider”是无效的连接字符串属性
  • 你能告诉我在下面的连接字符串中使用的是哪个提供商名称吗。
  • 在配置部分使用以下内容,并在连接字符串元素中引用相同的数据源别名,如上所述。
  • 收到此错误无法识别的配置部分 oracle.manageddataaccess.client。 my_app\web.config
【解决方案2】:
<?xml version="1.0"?>
<configuration>
    <configSections>
        <section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.122.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>
    </configSections>
    <oracle.manageddataaccess.client>
        <version number="*">
            <dataSources>
                <dataSource alias="UATDB" descriptor="(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = ipadd)(PORT = port))(CONNECT_DATA =(SERVER = DEDICATED)(SERVICE_NAME = orcle)))"/>
            </dataSources>
        </version>
    </oracle.manageddataaccess.client>
<connectionStrings> 
        <add name="Audit" connectionString="Provider=MSDAORA;Data Source=UATDB;User Id=userid;Password=password;Min Pool Size=10; Connection Lifetime=300;Connection Timeout=300;Incr Pool Size=5;Decr Pool Size=2;" providerName="Oracle.DataAccess.Client"/>
    </connectionStrings>
    <authentication mode="Forms">
            <forms loginUrl="~/Account/Login.aspx" timeout="2880"/>
        </authentication>
        <membership>
            <providers>
                <clear/>
                <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="false" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="6" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/"/>
            </providers>
        </membership>
        <profile>
            <providers>
                <clear/>
                <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/"/>
            </providers>
        </profile>
        <roleManager enabled="false">
            <providers>
                <clear/>
                <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/"/>
                <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/"/>
            </providers>
        </roleManager>
<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>
</configuration>

【讨论】:

  • 这是我的 web.config 文件。
  • 运行时显示错误----------->ORA-12154: TNS: 无法解析指定的连接标识符。
猜你喜欢
  • 2014-11-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-25
  • 1970-01-01
相关资源
最近更新 更多