Search code examples
c++oracleocci

OCCI exception: connect descriptor is too long (but not really)


I'm using OCCI for working with Oracle database by C++ and I'm trying to create a connection like this:

#include <occi.h>
using namespace oracle::occi;
using namespace std;

int main() {
    Environment *env = Environment::createEnvironment(Environment::DEFAULT);    
    Connection *con = env->createConnection(login, password, connection_string);
}

If I use connection_string:

string connection_string1 = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 
" + host_ + ")(PORT = " + port_ + "))(CONNECT_DATA = (SID = " + sid_ + ")))"; 

which is created using some variables, I got this exception:

ORA-12163: TNS:connect descriptor is too long

If I use the same string, but like:

string connection_string2 = "(DESCRIPTION = (ADDRESS = (PROTOCOL = 'TCP')(HOST 
= 'real.host.I.need.cz')(PORT = '1510'))(CONNECT_DATA = (SID = 'word')))";

with actual values, I got other exception:

ORA-12560: TNS:protocol adapter error

(connection_string1 == connection_string2 returns TRUE)

If I use ""(empty string) or "f"(anything), I got

ORA-12163: TNS:connect descriptor is too long

. This can't be true.

How can I find out, where the problem is?


Solution

  • We were connecting to server of version 11, but using Instant Client Version 12.2.0.1.0.

    Using Instant Client Version 11.2.0.4.0 solved the problem.