}catch(otl_exception &p) { cerr<<p.msg<<endl; cerr<<p.stm_text<<endl; cerr<<p.var_info<<endl; } oracledb.logoff(); return 0; }编译注意事项: a. 如果使用的Oracle oci是64位的,vs就要编译成64位的程序,如果编译成32位,会提示找不到Oracle的动态库。b.因为Oracle连接数据库较慢,有些会使用多线程,这时要注意线程安全问题.通过otl_initialize()函数设不同的参数来解决.// Threaded_mode = 1 means the multi-threaded mode, 0 -- the single threaded mode otl_connect::otl_initialize(0);
3. 用SYSDBA登录身份连接Oracle数据库当SYS用户连接Oracle时,如果用普通用户会报"ORA-28009 应当以sysdba或sysoper建立sys连接"错误.在session_begin中指定用户登录身份即可:db.session_begin(m_strUser.c_str(),m_strPassword.c_str(),0,OCI_SYSDBA);OCI_DEFAULT OCI_SYSDBA -- in this mode, the user is authenticated for SYSDBA access. OCI_SYSOPER -- in this mode, the user is authenticated for SYSOPER access.