Setting environment variables for connecting Instant Client to oracle

Source: Internet
Author: User
Tags file url

When the Instant Client connects to the oracle database, problems may occur when connecting directly. You must set the environment variables. Let's take a look at how to set the environment variables for the Instant Client to connect to oracle.

Recently, I wrote a code to use OCI to connect to the oracle database in the LAN. I thought it was as simple as a chain mysql database: After downloading the header file and library file Development Kit, I can directly connect to the database, as a result, I found that I was wrong, and oracle was not well known.

First, go to the oracle official website to download the C language library file and header file URL as follows, select the corresponding Instant Client Version (I downloaded all zip packages without downloading the rpm package, the rpm package should be configured during installation.
Http://www.oracle.com/technology/software/tech/oci/instantclient/index.html
The following is the version of linux i386
Http://www.oracle.com/technology/software/tech/oci/instantclient/htdocs/linuxsoft.html
Instant Client Package-Basic contains the dynamic library file libclntsh. so.11.1 (the latest version may be different) and load it to the dynamic library search path. Here we will not talk about the detailed steps. If you have any questions about Baidu/dog search, you cannot leave a message below.
* The Instant Client Package-SDK contains the header file.

Run the simple C link sequence error: ORA-12541: TNS: no listener network on the search said that the oracle Database listener is not configured or the listener is not started, the listener of the oracle 10g Database is obviously started, and the oracle client installed on another computer in the network can be linked with sqlplus and operated on the standard client of the database, which is 500 mb faster and too fat, I also downloaded the sqlplus Package: * Instant Client Package-SQL * Plus. After configuring the Package, I found that the connection to the oracle database by running the sqlplus command on the terminal is still incorrect:
ERROR:
ORA-12541: TNS: no listener

Even sqlplus reports the same error, which is not an oci problem, but an environment configuration problem of instant. Search Baidu/dog and find that the oracle instant configuration requires two environment variables: TNS_ADMIN and ORACLE_HOME. Using the export command is only valid for the currently running system. After the system is restarted, it will be gone. To make the configuration take effect permanently, edit it ~ /. Bashrc file, add two sentences at the end of the file:

 
 
  1. export TNS_ADMIN=/home/oracle/network/admin  
  2. export ORACLE_HOME=/home/oracle 

Note: the path of the ORACLE_HOME environment variable is to decompress the Instant Client Package-Basic zip Package. The path contains the so file jar files extracted from the Basic Package.

The TNS_ADMIN environment identifies tnsnames. ora file path, create a new network folder under the ORACLE_HOME path, and then create a new admin folder in the network folder with tnsnames in the admin folder. the ora file is enough. As for why TNS_ADMIN needs to be set like this, the hierarchical structure of the default oracle path is like this, so I also copy it. Theoretically, TNS_ADMIN does not have to be in the ORACLE_HOME path, I have never tried it. Anyone interested can try it. My tnsnames. ora is copied directly from other machines. The content is as follows:

 
 
  1. # tnsnames.ora Network Configuration File: /home/oracle/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora  
  2. TEST =  
  3. (DESCRIPTION =  
  4.     (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.8)(PORT = 1521))  
  5.     (CONNECT_DATA =  
  6.       (SERVER = DEDICATED)  
  7.       (SERVICE_NAME = test)  
  8.     )  
  9. )  
  10.  
  11. EXTPROC_CONNECTION_DATA =  
  12. (DESCRIPTION =  
  13.     (ADDRESS_LIST =  
  14.       (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))  
  15.     )  
  16.     (CONNECT_DATA =  
  17.       (SID = PLSExtProc)  
  18.       (PRESENTATION = RO)  
  19.     )  
  20. )  

After the preceding settings are configured, log out of the user and log on again to make the two environment variables ORACLE_HOME and TNS_ADMIN take effect. The check method is simple. Enter the following command on the terminal:

 
 
  1. [mgqw@localhost cutest]$ echo $ORACLE_HOME  
  2. /home/oracle  
  3. [mgqw@localhost cutest]$ echo $TNS_ADMIN  
  4. /home/oracle/network/admin 

If there is a path output as above, the configuration is successful. If there is no output, edit it again ~ /. Bashrc to see what went wrong.

After the check is complete, run sqlplus to log on to the database, and run C program to connect to the database.
 

ORACLE Database Encoding

Oracle date formatting implementation

Oracle memory structure-SGA

How to view the oracle database version

Learn about the ORACLE resource role

Related Article

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.