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:
- export TNS_ADMIN=/home/oracle/network/admin
- 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:
- # tnsnames.ora Network Configuration File: /home/oracle/oracle/product/10.2.0/db_1/network/admin/tnsnames.ora
- TEST =
- (DESCRIPTION =
- (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.8)(PORT = 1521))
- (CONNECT_DATA =
- (SERVER = DEDICATED)
- (SERVICE_NAME = test)
- )
- )
-
- EXTPROC_CONNECTION_DATA =
- (DESCRIPTION =
- (ADDRESS_LIST =
- (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1))
- )
- (CONNECT_DATA =
- (SID = PLSExtProc)
- (PRESENTATION = RO)
- )
- )
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:
- [mgqw@localhost cutest]$ echo $ORACLE_HOME
- /home/oracle
- [mgqw@localhost cutest]$ echo $TNS_ADMIN
- /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