Two methods for creating an Oracle database connection

Source: Internet
Author: User
If the database is not on the local host, you must configure the corresponding tns in $ ORACLE_HOMEnetworkadmintnsnames.ora before the program can access the database through the configured tns

If the database is not on the local host, you must configure the corresponding tns in $ ORACLE_HOME/network/admin/tnsnames. ora before the program can access the database through the configured tns

If the database is not on the local host, it must be in $ Oracle_HOME/network/admin/tnsnames. configure the corresponding tns in ora, and then the program can access the database through the configured tns. However, if java accesses oracle through the thin method, you can use the locally configured tns alias ,, you can also use the tns full resolution name and the full descriptor after the alias equals sign; as follows:

TESTCZ =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.70.9.12) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = TESTCZ)
)
)

For example.

There are now two databases

Adb. the username and password are adb and adb respectively. The tns name configured on the local host is tns_a and the host;

Bdb. the user name and password are bdb/bdb respectively. The tns name configured on the local host is tns_ B and the host B is located;

Now we need to create a dblink on the adb to connect to the bdb database;

Method 1:

Edit the tnsnames. ora file on host a to configure the tns alias tns_ B OF THE bdb database, as shown below:

Tns_ B =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.70.9.12) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = dbtestb)
)
)

Create a database connection as follows:

Create database link

Connect to bdb identified by bdb

Using 'tns _ B ';

Method 2:

If you do not have the permission to modify tnsnames. ora, you cannot create a tns alias for the adb database. Therefore, you can only use a full-write parsing symbol when creating the dblink. The method for creating a dblink is as follows:

Create database linkconnect to bdb identified by bdb

Using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.70.9.12) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = dbtestb)
)
)';

After creating a tns alias, you can use sqlplus username/password @ tnsname to test whether the created tns alias is correct.

A dblink example created in the production system:

Create database link NEW_DBLINK
Connect to AIIPS identified by "1qaz2wsx"
Using '(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP) (HOST = 10.70.193.12) (PORT = 1521 ))
)
(CONNECT_DATA =
(SERVICE_NAME = zjpub)
)
)';

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.