无法通过 OLE DB 连接到 Oracle 11g
已解决:我的 VC++ 应用程序是 32 位,而我的 Oracle DB 是 64 位。我最初认为客户端可以使用两个版本的 Oracle,但事实并非如此。于是我通过重新安装Oracle 11g2 32位解决了这个问题。
我正在尝试通过 C++ 中的 Visual Studio 2008 连接到测试 Oracle 11g2 数据库。 我的数据库实例名称是 ORCL.TEST.DB,出于测试目的,我尝试使用用户:SYSTEM 和密码:admin 进行连接。 我还使用 Oracle OLE DB 连接器。
正如您所看到的,我并没有尝试任何花哨的事情,我只是想成功连接。
CDataSource ds;
CSession session;
int _tmain(int argc, _TCHAR* argv[])
{
try{
// fire up COM
HRESULT hr = CoInitialize(0);
if(FAILED(hr))
{
cout << "Can't start COM!? " << endl;
return -1;
}
/// connect to the database
//hr = ds.Open(L"OraOLEDB.Oracle", _T("ORCL"), _T("SYSTEM"), _T("admin"));
hr = ds.OpenFromInitializationString(L"Provider=OraOLEDB.Oracle;Data Source=ORCL.TEST.DB;User Id=SYSTEM;Password=admin");
if(FAILED(hr))
{
////////////////THIS IS WHERE IT ENDS UP
cout << "Can't open db" << endl << hr << endl;
return -1;
}
}
catch(...){
cout << "Unknown failure" << endl;
return -1;
}
return 0;
}
hr包含的错误代码是80004005,即E_FAIL(未指定的故障)。
起初我以为这是 32 与 64 的问题(64 位操作系统和 64 位 Oracle,但 Visual Studio 2008 中的 32 位 C++ 编译器)。所以我安装了Oracle的Instant Client 32位但它并没有解决我的问题。
有什么想法吗?
SOLVED: My VC++ application was in 32 bit and my Oracle DB was in 64 bit. I initially though that the client would work with both versions of Oracle, however, it doesn't. I thus solved the problem by reinstalling Oracle 11g2 32bit.
I'm trying to connect to a test Oracle 11g2 database via Visual Studio 2008 in C++.
My database instance name is ORCL.TEST.DB, and the for testing purposes, I try to connect with user:SYSTEM and password:admin.
I'm also using the Oracle OLE DB connector.
As you can see, I'm not trying anything fancy, I'm merely trying to successfully connect.
CDataSource ds;
CSession session;
int _tmain(int argc, _TCHAR* argv[])
{
try{
// fire up COM
HRESULT hr = CoInitialize(0);
if(FAILED(hr))
{
cout << "Can't start COM!? " << endl;
return -1;
}
/// connect to the database
//hr = ds.Open(L"OraOLEDB.Oracle", _T("ORCL"), _T("SYSTEM"), _T("admin"));
hr = ds.OpenFromInitializationString(L"Provider=OraOLEDB.Oracle;Data Source=ORCL.TEST.DB;User Id=SYSTEM;Password=admin");
if(FAILED(hr))
{
////////////////THIS IS WHERE IT ENDS UP
cout << "Can't open db" << endl << hr << endl;
return -1;
}
}
catch(...){
cout << "Unknown failure" << endl;
return -1;
}
return 0;
}
The error code hr contains is 80004005, which is E_FAIL (unspecified failure).
At first I thought it was a 32 vs 64 issue (64bit OS and 64bit Oracle, but 32bit C++ compiler in Visual Studio 2008). So I installed Oracle's Instant Client 32bit but it did not solve my problem.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
用于 Oracle 的 Microsoft ODBC 驱动程序非常旧且不受支持。对 Oracle 数据库和驱动程序的支持位于 Oracle 网站。
我建议您访问 Oracle 站点 Oracle Network 并注册一个帐户加入 Oracle 网络后,请检查 Visual Studio Tools for Oracle 的下载部分,并查找适用于 X64 或 X86 的 ODAC112021xcopy.zip 包,其中包含适用于 Windows 的更新的运行时驱动程序。
下载运行时驱动程序后,请阅读 oracle 的安装指南。Oracle 的新驱动程序将出现在 ODBC 管理器中,然后您可以更新“您的连接字符串”以使用新驱动程序。如果您无法连接到 Oracle 数据库问题通常是 tns.listener 连接设置。
典型设置使用 XE.NAME 作为服务器实例。您需要打开端口 1521 的防火墙以允许连接。
如果您查看 oraXXXX 消息的 ora 错误并搜索(Goolge 或 Bing),Web 上会显示如何更改 Oracle 数据库引擎的 tns 侦听器。
如果您对连接字符串有疑问,您可以(Google 或 Bing)连接字符串。
如果您遇到 IIS 服务器错误,请阅读 IIS Net 库指南以启用和打开“失败请求跟踪”
The Microsoft ODBC driver for Oracle is very old and not supported.The support for Oracle database and drivers is at Oracles Web Site.
I suggest you visit Oracle Site Oracle Network and register for an Account which is no cost.Then after you have joined the Oracle Network check the download sectio for Visual Studio Tools for Oracle and look for the ODAC112021xcopy.zip package for X64 or X86 which contains the updated runtime drivers for Windows.
After you have downloaded the runtime drivers read the guides at oracle for install.The new driver for Oracle will appear in the ODBC manager you then can update "your connection string" to use the new driver.If you can not connnect to the Oracle database the problem typically are the tns.listener connection settings.
Typical settings use XE.NAME for the server instance. You will need to open the firewall for port 1521 to allow connections.
If you look at the ora error which is oraXXXX message and search (Goolge or Bing) there are place on the Web that show how to change the tns listener for the Oracle Database engine.
If you have problems with the connection string you can (Google or Bing) Connection Strings.
If you have IIS Server errors then read the IIS Net library guides for Enabling and Turning on "Failed Request Tracing"