VC++ 连接oracle数据库 open()异常
1、服务器安装有oracle 11G数据库。
2、我机器(Win7 64)上安装了oracle 11g client (安装在D盘,vs在C盘)。
3.在Oracle Net Manager配置好服务,服务名dsmp,用sqlplus, dsmp/dsmp123@dsmp 能连接上。
4、代码总是连接失败(调用Open()时抛出异常,错误代码0x800A0E7A),“未找到提供程序,该程序可能未正确安装“。)
网上查的:regsvr32 msado15.dll ----- 提示成功了
regsvr32 D:\app\h0ngming\product\11.2.0\client_1\BIN\OraOLEDB11.dll
----- 提示成功了
代码:
#import "c:\Program Files (x86)\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
CoInitialize(NULL);
m_pConnection.CreateInstance(__uuidof(Connection));
CString strUser = "dsmp";
CString strPwd = "dsmp123";
CString strSource = "(DESCRIPTION =(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.32.147)(PORT=1521)))(CONNECT_DATA=(SID = dsmp)))";
//CString strSource = ”dsmp“
try
{
CString strConnect;
strConnect.Format(_T("Provider=OraOLEDB.Oracle.1;Password=%s;Persist Security Info=True;User ID=%s;Data Source=%s"),strPwd, strUser, strSource);
//设置连接时间
m_pConnection->ConnectionTimeout = 5;
//连接数据库
HRESULT _hr = m_pConnection->Open((_bstr_t)strConnect,(_bstr_t)_T(""), (_bstr_t)_T(""), adConnectUnspecified);
}
catch (_com_error e)
{
CString errormessage;
CString str = "连接数据库失败:错误码%s";
errormessage.Format(str,e.ErrorMessage());
AfxMessageBox(errormessage);
//CString cstr = (CString)e.Description();
AfxMessageBox(e.Description());
return FALSE;
}
我机器上用OracleSQLHandler 和 PL/SQL 、sqlplus 都能连接上。
哪位大侠知道的还请赐教一下!不胜感激!