Reputation:
I have a cloud database with Oracle and I'm trying to learn how to execute SQL commands within my c++ application in Windows.
Here's what I've tried.
1) Using Instant Client (OCCI)
Environment* env;
Connection* conn;
env = Environment::createEnvironment(Environment::DEFAULT);
conn = env->createConnection ("username", "password", "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST=myserver111) (PORT=5521))(CONNECT_DATA = (SERVICE_NAME = bjava21)))");
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
2) Using ODBC
3) Using Oracle Developer Tools for Visual Studio
Update
createConnection("username", "password", "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST=myserver111) (PORT=5521))(CONNECT_DATA = (SERVICE_NAME = bjava21)))")
createConnection("username", "password", "//host:[port][/service name]")
createConnection("username", "password", "xxx_low")
createConnection("username", "password", "protocol://host:port/service_name?wallet_location=/my/dir&retry_count=N&retry_delay=N")
createConnection("username", "password", "username/password@xxx_low")
Error While Debugging:
Unhandled exception in exe: Microsoft C++ exception: oracle::occi::SQLException at memory location
Full Code
#include <occi.h>
using namespace oracle::occi;
int main() {
Environment* env;
Connection* conn;
env = Environment::createEnvironment(Environment::DEFAULT);
conn = env->createConnection("username", "password", "(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp) (HOST=myserver111) (PORT=5521))(CONNECT_DATA = (SERVICE_NAME = bjava21)))");
env->terminateConnection(conn);
Environment::terminateEnvironment(env);
return 0;
}
Upvotes: 0
Views: 1130
Reputation: 10711
With Instant Client in general:
For cloud:
ODBC will be exactly the same. Once you have the wallet files extracted to the default network/admin subdirectory you just need to connect with the DB credentials and use a network alias from the tnsnames.ora file.
More info is in my blog post How to connect to Oracle Autonomous Cloud Databases.
Official doc is in Connect to Autonomous Database Using Oracle Database Tools
Upvotes: 1