问题
I'm trying to run the following test program on Ubuntu to connect to an oracle database using the instant client OCCI library.
#include <iostream>
#include <occi.h>
using namespace oracle::occi;
int main() {
Environment *env = Environment::createEnvironment(Environment::DEFAULT);
Connection *conn = env->createConnection( "user", "1234" );
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
}
There are no errors when compiling
g++ main.cpp -L ~/instantclient_12_2 -locci -lclntsh -I ~/instantclient_12_2/sdk/include
But when running I get
terminate called after throwing an instance of 'oracle::occi::SQLException'
what(): ORA-24960: the attribute OCI_ATTR_USERNAME is greater than the maximum allowable length of 255
Aborted
I'm running Ubuntu 16.04, gcc 5.4.0 and I get the same result with instant client 11.2 and 12.2.
This has been asked before: https://stackoverflow.com/questions/40022118/ora-24960-the-attribute-oci-attr-username-is-greater-than-the-maximum but the answer is not applicable to linux (or I'm missing the point).
Any help would be appreciated.
回答1:
Solved the problem by reverting to an older compiler.
$ sudo apt-get install g++-4.8
$ g++-4.8 main.cpp -L ~/instantclient_12_2 -locci -lclntsh -I ~/instantclient_12_2/sdk/include
Perhaps the latest compiler and libraries is incompatible with those used to build the OCCI libraries.
回答2:
If you are using CMake
1) Add this line on your CMakeLists.txt to specify the compiler to use
SET(CMAKE_CXX_COMPILER /usr/bin/g++-4.8)
P.S You may have to install g++-4.8
(apt-get install g++-4.8)
来源:https://stackoverflow.com/questions/42890553/ubuntu-ora-24960-the-attribute-oci-attr-username-is-greater-than-the-maximum-al