You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用OCCI连接Oracle数据库遇报错求助

Hey there, let's tackle those ORA errors you're hitting while trying to connect to Oracle via OCCI in Visual Studio 2017. I've worked through similar connection issues before, so here's what to check and fix:

1. Fix the Syntax in Your Connection Descriptor

The first red flag is the extra single quotes around parameter values in your connection string. Oracle doesn’t require (or expect) quotes around values like TCP, my.host.cz, or 1510 in the TNS descriptor. These quotes add unnecessary length (triggering ORA-12163) and can cause parsing issues that lead to ORA-12560.

Here’s the corrected code with quotes removed:

Environment *env = Environment::createEnvironment(Environment::DEFAULT); 
Connection *con; 
con = env->createConnection(Config::login, Config::password, 
    "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = my.host.cz)(PORT = 1510))(CONNECT_DATA = (SID = mySid)))");

2. Simplify with a TNS Alias (Avoid Long Descriptors)

If the corrected string still throws ORA-12163, using a TNS alias is a reliable fix. This replaces the long descriptor with a short name, eliminating length issues and reducing formatting errors:

  • Open your tnsnames.ora file (usually located in ORACLE_HOME\network\admin or the path set by the TNS_ADMIN environment variable).
  • Add an entry for your database:
    MY_DB_ALIAS =
      (DESCRIPTION =
        (ADDRESS = (PROTOCOL = TCP)(HOST = my.host.cz)(PORT = 1510))
        (CONNECT_DATA =
          (SID = mySid)
        )
      )
    
  • Update your code to use the alias:
    con = env->createConnection(Config::login, Config::password, "MY_DB_ALIAS");
    

3. Troubleshoot ORA-12560 (Protocol Adapter Error)

This error often stems from mismatched configurations rather than the connection string itself:

  • Platform Bitness Match: Ensure your VS project’s target platform (x86/x64) exactly matches the bitness of your Oracle Client installation. For example, a 64-bit client requires a VS project set to x64.
  • Environment Variables: Verify ORACLE_HOME points to your Oracle Client installation directory, and TNS_ADMIN (if used) points to the folder containing tnsnames.ora. Restart VS after changing these variables to apply the settings.
  • Client-Server Compatibility: Use an OCCI library version that’s compatible with your Oracle Server version. Sticking to the same major version (e.g., 12c client for a 12c server) avoids compatibility gaps.

4. Validate Connection with sqlplus First

Before debugging code, test your connection using Oracle’s sqlplus tool to rule out network or credential issues:

sqlplus your_username/your_password@(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = my.host.cz)(PORT = 1510))(CONNECT_DATA = (SID = mySid)))

If sqlplus fails to connect, fix the underlying network/credential problem first. If it works, the issue lies in your VS project’s OCCI configuration.


内容的提问来源于stack exchange,提问作者Evka'S

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 08:29:17