0

I am trying to use a SELECT query to populate a table in DB2 using a database link to DB1. I am using Oracle SQL Developer on a Windows 7 VM. I connect to DB2, and run the following query.

INSERT INTO DB_NAME.TABLE_NAME (SELECT * FROM DB_NAME.TABLE_NAME@LINK_TO_DB1);

Every time, no matter what, I get the following error:

ORA-12154: TNS:could not resolve the connect identifier specified
12154. 00000 -  "TNS:could not resolve the connect identifier specified"
*Cause:    A connection to a database or other service was requested using
           a connect identifier, and the connect identifier specified could not
           be resolved into a connect descriptor using one of the naming methods
           configured. For example, if the type of connect identifier used was a
           net service name then the net service name could not be found in a
           naming method repository, or the repository could not be
           located or reached.
*Action:   
           - If you are using local naming (TNSNAMES.ORA file):
           - Make sure that "TNSNAMES" is listed as one of the values of the
           NAMES.DIRECTORY_PATH parameter in the Oracle Net profile
           (SQLNET.ORA)
           - Verify that a TNSNAMES.ORA file exists and is in the proper
           directory and is accessible.
           - Check that the net service name used as the connect identifier
           exists in the TNSNAMES.ORA file.
           - Make sure there are no syntax errors anywhere in the TNSNAMES.ORA
           file.  Look for unmatched parentheses or stray characters. Errors
           in a TNSNAMES.ORA file may make it unusable.
           - If you are using directory naming:
           - Verify that "LDAP" is listed as one of the values of the
           NAMES.DIRETORY_PATH parameter in the Oracle Net profile
           (SQLNET.ORA).
           - Verify that the LDAP directory server is up and that it is
           accessible.
           - Verify that the net service name or database name used as the
           connect identifier is configured in the directory.
           - Verify that the default context being used is correct by
           specifying a fully qualified net service name or a full LDAP DN
           as the connect identifier
           - If you are using easy connect naming:
           - Verify that "EZCONNECT" is listed as one of the values of the
           NAMES.DIRETORY_PATH parameter in the Oracle Net profile
           (SQLNET.ORA).
           - Make sure the host, port and service name specified
           are correct.
           - Try enclosing the connect identifier in quote marks.
Error at Line: 1 Column: 30

I've been googling and attempting different solutions for 2 days with no luck. I've done all of the following:

  • Set PATH environment variable to C:\Oracle\instantclient_11_2
  • Set ORACLE_HOME environment variable to C:\Oracle\instantclient_11_2
  • Set TNS_ADMIN environment variable to C:\Oracle\instantclient_11_2\network\admin
  • Created a tnsnames.ora file with the correct connection information in C:\Oracle\instantclient_11_2\network\admin
  • Set the Tnsnames Directory field in SQL Developer (Tools > Preferences > Database > Advanced) to C:\Oracle\instantclient_11_2\network\admin

I am at a loss as to why these database links aren't working. Does anyone have any advice?

2
  • Are there three machines involved here? A client machine, a machine for DB1, and a machine for DB2? Do you have one machine with three Oracle Homes (one for the client, one for the DB1 database, and one for the DB2 database)? It seems unlikely that you'd do an Instant Client install on a machine that is already running the database so I'm guessing multiple machines are involved. If so, the tnsnames.ora file that needs to have DB2's connection information would need to exist on the machine (and Oracle Home) running DB1. Your client's TNS settings are irrelevant. Commented Feb 17, 2015 at 23:13
  • Hi. Yes three machines are involved. DB1 and DB2 exist internally at my client's office. I am not certain if they reside on separate hardware. I have very limited access to these databases. I have SQL Developer installed on my laptop in a Windows 7 VM. I receive the error above when I attempt to run that insert statement when connected to DB2.
    – Kelly Cook
    Commented Feb 17, 2015 at 23:18

2 Answers 2

0

If you want to have a database link on DB1 that points to DB2, DB1 would need to be able to resolve whatever TNS alias you specify in the database link definition. Assuming that you are using tnsnames.ora files everywhere for TNS name resolution, that would mean that the tnsnames.ora file on DB1 would need to have an entry that points to DB2. The TNS alias you specify in your CREATE DATABASE LINK statement would need to reference that TNS alias (which could be different than the alias for DB2 that you have created on your local machine). If you have limited access to the machine where DB1 resides, you would most likely need the DBA for DB1 to ensure that the TNS alias gets created appropriately.

3
  • The DBAs set up DB1 and DB2, as well as the database links that I am to use. I don't have access to edit any files on DB1 or DB2 servers. The DBAs have told me that the issue is on my machine, and I am having a hard time understanding why my machine is the issue.
    – Kelly Cook
    Commented Feb 17, 2015 at 23:48
  • 1
    @KellyCook - The error you are getting cannot possibly be the result of something being wrong on the client machine (assuming that it is actually the INSERT statement that throws the error). The error you're getting indicates that the database link is set up incorrectly. Commented Feb 17, 2015 at 23:49
  • That is what I initially thought when I was told that the issue was local to my machine. Thank you for confirming that for me. I do believe this to be true, especially after troubleshooting and researching for 3 days.
    – Kelly Cook
    Commented Feb 18, 2015 at 0:02
0

You can create the database link using a full TNS connection descriptor, to workaround the requirement of needing tnsnames.ora entries on the DB box.

For example:

create database link db2full
connect to db2 identified by db2pass
using
'(DESCRIPTION=
   (ADDRESS=
   (PROTOCOL=TCP)
   (HOST=db2host)
   (PORT=1521))
   (CONNECT_DATA=
   (SID=db2)))';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.