ORA-12154 could not resolve the connect identifier specified

前端 未结 14 2773
南旧
南旧 2020-12-06 09:18

I have switched over to the 64bit Windows 7 and created a simple web app to test the connection to the database. I am using VS 2010 - plain asp.net web project and I am runn

相关标签:
14条回答
  • 2020-12-06 09:53

    I have an Entity Framework web application that works on my local machine, but this error appears when pushed to another environment. There are other non-Entity Framework applications that work, and I'm able to connect with sqlplus.

    Using sysinternals Process Monitor shows that tns names file is not being loaded correctly:

    Following the documentation I tried to add a section giving the location of the tnsnames file like so:

    <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="*">
          <settings>
            <setting name="TNS_ADMIN" value="C:\Oracle\product\12.1.0\client_1\Network\Admin"/>
          </settings>
        </version>
      </oracle.manageddataaccess.client>
      
    <configuration>
    

    However, this resulted in an immediate 500 server error.

    Further investigation showed that the dll I was packaging with the web application was version 4.122.1.0, while the Oracle client environment installed on the machine was 4.121.2.0. As explained in the Oracle EntityFramework package documentation

    Note: If your application is a web application and the above entry was added to a web.config and the same config section handler for "oracle.manageddataaccess.client" also exists in machine.config but the "Version" attribute values are different, an error message of "There is a duplicate 'oracle.manageddataaccess.client' section defined." may be observed at runtime. If so, the config section handler entry in the machine.config for "oracle.manageddataaccess.client" has to be removed from the machine.config for the web application to not encounter this error. But given that there may be other applications on the machine that depended on this entry in the machine.config, this config section handler entry may need to be moved to all of the application's .NET config file on that machine that depend on it.

    I attempted to add a separate version section in the .NET machine.config without success (there existed a section for version 4.121.2.0 and I added a section for version 4.122.1.0). After I removed the "oracle.manageddataaccess.client" section from the machine.config, the above addition to the web.config resolved ORA-12154.

    Solution #1 summary:

    1. Remove "oracle.manageddataaccess.client" from .NET machine.config
    2. Give TNS_ADMIN configuration setting in web.config as above

    Solution 2

    While researching this problem I found that the TNS_ADMIN environmental variable was not set. I created a new environmental variable called TNS_ADMIN and set the value to "C:\Oracle\product\12.1.0\client_1\Network\Admin". I removed the web.config changes, and removed the "oracle.manageddataaccess.client" section from .NET machine.config, but still received ORA-12154. Only after I restarted the machine did this resolve the issue.

    Solution #2 summary:

    1. Create a new environmental variable called TNS_ADMIN and set the value to "C:\Oracle\product\12.1.0\client_1\Network\Admin"
    2. Restart machine

    Solution 3

    I added an entry for the correct version in the registry and this resolved the issue:

    HKLM\Software\Wow6432Node\Oracle\ODP.NET.Managed\4.121.2.0  
    

    The name of the key is TNS_ADMIN and this points to the folder containing the tnsnames file:

    C:\Oracle\product\12.1.0\client_1\network 
    

    Not the C:\Oracle\product\12.1.0\client_1\network\admin folder.

    0 讨论(0)
  • 2020-12-06 09:55

    If you are using LDAP, make sure that the environment variable "TNS_ADMIN" exists and points to the folder containing the file "ldap.ora".

    If this variable does not exist, create it and restart Visual Studio.

    0 讨论(0)
  • 2020-12-06 09:56

    There can be so many issues but if you are using oracle 10g , uninstall oracle 10g and also remove the value from registry and install oracle 11g. But if you are using oracle 11g , first go and check on registry if it is pointing to right home. Sometimes there can be more than one home because you install sql developer again and again . In that case either you can remove unnecessary home registry value or you can add tns and sql.net file to all of those home, that might resolve the issue. I resolved mine in that way.

    0 讨论(0)
  • 2020-12-06 09:56

    This is an old question but Oracle's latest installers are no improvement, so I recently found myself back in this swamp, thrashing around for several days ...

    My scenario was SQL Server 2016 RTM. 32-bit Oracle 12c Open Client + ODAC was eventually working fine for Visual Studio Report Designer and Integration Services designer, and also SSIS packages run through SQL Server Agent (with 32-bit option). 64-bit was working fine for Report Portal when defining and Testing an Data Source, but running the reports always gave the dreaded "ORA-12154" error.

    My final solution was to switch to an EZCONNECT connection string - this avoids the TNSNAMES mess altogether. Here's a link to a detailed description, but it's basically just: host:port/sid

    http://www.oracledistilled.com/oracle-database/oracle-net/using-easy-connect-ezconnect-naming-method-to-connect-to-oracle-databases/

    In case it helps anyone in the future (or I get stuck on this again), here are my Oracle install steps (the full horror):

    Install Oracle drivers: Oracle Client 12c (32-bit) plus ODAC.

    a. Download and unzip the following files from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/database12c-win64-download-2297732.html and http://www.oracle.com/technetwork/database/windows/downloads/utilsoft-087491.html ):

    i. winnt_12102_client32.zip

    ii. ODAC112040Xcopy_32bit.zip

    b. Run winnt_12102_client32\client32\setup.exe. For the Installation Type, choose Admin. For the installation location enter C:\Oracle\Oracle12. Accept other defaults.

    c. Start a Command Prompt “As Administrator” and change directory (cd) to your ODAC112040Xcopy_32bit folder.

    d. Enter the command: install.bat all C:\Oracle\Oracle12 odac

    e. Copy the tnsnames.ora file from another machine to these folders: *

    i. C:\Oracle\Oracle12\network\admin *

    ii. C:\Oracle\Oracle12\product\12.1.0\client_1\network\admin *

    Install Oracle Client 12c (x64) plus ODAC

    a. Download and unzip the following files from http://www.oracle.com/technetwork/database/enterprise-edition/downloads/database12c-win64-download-2297732.html and http://www.oracle.com/technetwork/database/windows/downloads/index-090165.html ):

    i. winx64_12102_client.zip

    ii. ODAC121024Xcopy_x64.zip

    b. Run winx64_12102_client\client\setup.exe. For the Installation Type, choose Admin. For the installation location enter C:\Oracle\Oracle12_x64. Accept other defaults.

    c. Start a Command Prompt “As Administrator” and change directory (cd) to the C:\Software\Oracle Client\ODAC121024Xcopy_x64 folder.

    d. Enter the command: install.bat all C:\Oracle\Oracle12_x64 odac

    e. Copy the tnsnames.ora file from another machine to these folders: *

    i. C:\Oracle\Oracle12_x64\network\admin *

    ii. C:\Oracle\Oracle12_x64\product\12.1.0\client_1\network\admin *

    * If you are going with the EZCONNECT method, then these steps are not required.

    The ODAC installs are tricky and obscure - thanks to Dan English who gave me the method (detailed above) for that.

    0 讨论(0)
  • 2020-12-06 09:58

    Had a similar issue, only my web app was fine and it was SQLPlus that was giving me issues connecting, and the ORA-12154 could not resolve the connect identifier specified error. I had 11g and 12 Oracle clients installed. My environment variables were all set to point at my 12 instance:

    • ORACLE_HOME = C:\oracle\product\12
    • PATH = C:\oracle\product\12\bin;....
    • TNS_ADMIN = C:\oracle\product\12\network\admin

    There is also a registry entry required at HKLM\Software\Oracle\KEY_OraClient12Home1, a string entry of TNS_ADMIN with the same path as the environment variable.

    I have a tnsnames.ora at both C:\oracle\product\11\network\admin and C:\oracle\product\12\network\admin. As far as I know, both my web app and the 12 SQLPlus client I was using should have been using all 12 version variables.

    My troubleshooting steps:

    • Change all environmental variables above from 12 to 11.
    • Connect with 11g's SQLPlus (worked!)
    • Change all environmental variables above back from 11 to 12.
    • Connect with 12's SQLPlus again (worked!)

    So I don't really know what caused 12's SQLPlus to stop connecting, but this kind of reset may work for someone, so thought I'd document it here.

    0 讨论(0)
  • 2020-12-06 10:01

    use process monitor and search for name not found log for tnsnames.ora file.

    check your environment variables. if not valid than uninstall all oracle client and reinstall.

    0 讨论(0)
提交回复
热议问题