我想使用OCILIB
https://vrogier.github.io/ocilib/doc/html/group___ocilib_cpp_api_demo_list_application.html
使用此第一个示例代码,在Visual Studio 2019
上运行
// dbconnect.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include <iostream>
#include <stdio.h>
#include "ocilib.hpp"
using namespace ocilib;
//Declaration:
int test_odbc()
{
try
{
Environment::Initialize();
Connection con("ORCL", "test", "test");
Statement st(con);
st.Execute("select intcol, strcol from table");
Resultset rs = st.GetResultset();
while (rs.Next())
{
std::cout << rs.Get<int>(1) << " - " << rs.Get<ostring>(2) << std::endl;
}
}
catch (std::exception& ex)
{
std::cout << ex.what() << std::endl;
}
Environment::Cleanup();
return EXIT_SUCCESS;
}
int main()
{
test_odbc();
}
用于连接到本地安装的Oracle 12数据库。
在Connection con ...我得到:
ORA-12154: TNS:could not resolve the connect identifier specified
与我使用orcl.ad001.siemens.net
代替ORCL
时相同。
我可以通过SQLDeveloper进行如下连接:
tns.ora如下:
# tnsnames.ora Network Configuration File: C:\app\atw11a92\virtual\product\12.2.0\dbhome_1\network\admin\tnsnames.ora
# Generated by Oracle configuration tools.
LISTENER_ORCL =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
(SID = CLRExtProc)
(PRESENTATION = RO)
)
)
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = orcl.ad001.siemens.net)
)
)
我可以发送ORCL:
C:\Users\atw11a92>tnsping ORCL
TNS Ping Utility for 64-bit Windows: Version 12.2.0.1.0 - Production on 12-DEC-2019 11:12:09
Copyright (c) 1997, 2016, Oracle. All rights reserved.
Used parameter files:
C:\app\atw11a92\virtual\product\12.2.0\dbhome_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl.ad001.siemens.net)))
OK (0 msec)
C:\Users\atw11a92>
任何想法?我完全泄气...
orcl.ad001.siemens.net
和ORCL
不是SID。它们是服务名称。因此,在第一个屏幕上,使用服务名称而不是SID。输入字段SID CLRExtProc