Oracle C++ OCI Database connection

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:

1
2
3
4
5
6
7
8
9
10
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 :

1
2
3
4
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:

1
2
3
4
5
6
7
8
9
10
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.

What am I missing here? http://docs.oracle.com/cd/B28359_01/appdev.111/b28390/reference014.htm#CHEEGFAI
Should I post additional information. Is my rep not high enough? What should I do to get replies on this forum?
Not in a hurry, are you. The problem might be in what arguments env.createConnection() is expecting. Does it take a standard::string? or a const char*?
@roymustang86
First, you have to have patience. I have found your question on this site and two stackoverflow posts. Programmers have lives and don't sit on the site waiting to help people.

Second, what is Environment& _env? According to your link it links to:
1
2
3
4
Connection * createConnection(
   const string &userName,
   const string &password,
   const string &connectString="")=0;
Last edited on by closed account z6A9GNh0
@BHXSpecter:

I was in a bit of a hurry, it was just that, I did not receive any sort of activity in my stackoverflow for over 3 days.

I figured what the problem was, the dbName I am passing to the method is a const char *, and when it gets cast to a const string &, it gets an additional character added to the end, which is probably a newline character or something.

How do I close this post?
Mark it as answered. I'm glad you found your answer!
Topic archived. No new replies allowed.