简体   繁体   中英

C program exits giving error ORA-12162: TNS:net service name is incorrectly specified

I am working on a remote red-hat server and there I'm developing ac application to insert data in to a remote oracle database. So first i installed the OCI instant client rpm on the server and tried to compile a sample program. after certain linkages I could compile it. But then when I am going to run it. It exits giving an error saying

ORA-12162: TNS:net service name is incorrectly specified

The sample code I used is from the blog (refer to this code in case you need to clarify the things.where I'm quoting only few pieces to this post) René Nyffenegger's collection of things on the web René Nyffenegger on Oracle

(refer to this code in case you need to clarify the things.where I'm quoting only few pieces to this post)

In the code I added some prints to check for the error And it seems like It gets stuck in the OCIServerAttach() function r gives a printed walue of -1

r=OCIServerAttach(srv, err,  dbname, strlen(dbname), (ub4) OCI_DEFAULT);
printf("r value %d",r);

if (r != OCI_SUCCESS) {
checkerr(err, r);
goto clean_up;
}

Another point is that in the compilation process it gives a warning saying that a certain libry is not include. but the exicutable file is created. Here is the massage I get in the compilation process.

[laksithe@loancust ~]$ gcc -L$ORACLE_HOME/lib/ -L$ORACLE_HOME/rdbms/lib/ -o oci_test oci_test.o -L/usr/lib/oracle/12.1/client64/lib  -lclntsh   `cat $ORACLE_HOME/lib/sysliblist`
cat: /lib/sysliblist: No such file or directory

Going through the web I found that by creating a tnsnames.ora file with the connection details I could solve the problem. But even It didn't work for me. Here is the link for that blog blog

It has been a week since this error and I cold'nt solve it. could someone please help me.

connection string format I used is abc.ghi.com:1521/JKLMN

My recommendation is to bypass tnsnames completely. Oracle has always allowed you to put in the direct connection details, but EZConnect makes that even easier.

When you format your connection string, instead of listing the TNS name, use the actual connection properties in the following format:

servername:port/service name

For Example

MyOracle.MyCompany.Com:1521/SalesReporting

Your connection string might also require direct=true , but I'm honestly not sure.

I like the idea of tnsnames, but it's a double edged sword. When it works, it's great. When it doesn't, you want to throw something. With EZConnect, it always works.

By the way, if you don't know the properties of the three items above, find a machine that connect via tnsnames and:

tnsping <your TNS-named database>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM