0
votes

I am trying to port an application from Solaris to Linux.

On Solaris, I used the Sun Studio C++ compiler, and on Linux, I used the Intel C++ compiler.

Now, I am facing the following problem while connecting to oracle database:

 OCIDBConnection::OCIDBConnection(
 Environment& _env, const STRING& dbName, const STRING& user, const STRING& password) 
: env(_env)
{
 COUT<<"username "<<user<<ENDL;
 COUT<<"password "<<password<<ENDL;
 COUT<<"dbname "<<dbName<<ENDL;
 conn = env.createConnection(user, password, dbName);

}

The output comes out like :

username roymustang9
password roymustang9
dbname roydb
[2013-11-12 15:39:23]>>FATAL<<: Login failed.

And on printing the SQLException, I find:

ORA-12154: TNS:could not resolve the connect identifier specified which is ridiculous, because the name exists in the tnanames.ora, and the connection details are right. Infact, when I hardcode the values, it goes through fine:

 OCIDBConnection::OCIDBConnection(
 Environment& _env, const STRING& dbName, const STRING& user, const STRING& password) 
 : env(_env)
{
 COUT<<"username "<<user<<ENDL;
 COUT<<"password "<<password<<ENDL;
 COUT<<"dbname "<<dbName<<ENDL;
 conn = env.createConnection("roymustang9", "roymustang9", "roydb");

}

STRING is a typedef defined as std::string. COUT and ENDL are typedefs of std::cout and std::endl as well.

What am I missing here? http://docs.oracle.com/cd/B28359_01/appdev.111/b28390/reference014.htm#CHEEGFAI

2
Check for whitespace and unprintable characters in your strings.Peter

2 Answers

1
votes

It seems that string dbName is malformed.. maybe it have new-line char at the end. Try to remove it:

dbName.erase(std::remove(dbName.begin(), dbName.end(), '\n'), dbName.end());
0
votes

The dbname can also be "roydb.world" or something like that

  • first check your env variables ORACLE_HOME and TNS_ADMIN
  • then check output from tnsping
  • then check is you're able connect using sqlplus