Oracle Connection with SQLAPI++

163 Views Asked by At

I'm trying to connect my c++ code with oracle using SQLAPI++ but it gives me the error TNS:could not resolve the connect identifier specified

My code is like so:

con.Connect( "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST=192.168.1.XXX) (PORT=1521))(CONNECT_DATA = (SERVICE_NAME = SERVICE_NAME )))", "UsrName", "Password", SA_Oracle_Client );

if I only use the same code but the username and password are equal to nothing like this:

con.Connect( "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST=192.168.1.XXX) (PORT=1521))(CONNECT_DATA = (SERVICE_NAME = SERVICE_NAME )))", "", "", SA_Oracle_Client );

the compiler gives me an ORA-01017: Invalid username / password; connection refused\n error.

1

There are 1 best solutions below

0
On

You may give instant client syntax a try:

[//]host[:port][/service name]

This I've used with SQLAPI++ successfully. The string you've used is expected to occur in tnsnames.ora and you refer to this entry via a so called tnsname. If you can't change the tnsnames.ora stored in Oracle installation you're using then you can instruct the Oracle API to pick the file up form another location by defining the environmanet varable TNS_ADMIN. Set this to a directory were your own tnsnames.ora file exists.