if (!AfxOleInit())
{
AfxMessageBox( "ole 初始化错误 ");
return FALSE;
}
try//连接数据库
{
m_pConnection->ConnectionTimeout =5;//设置超时连接
m_pConnection.CreateInstance(__uuidof(Connection));
_bstr_t strConnect=_T("DSN=OraOLEDB.Oracle.1;User ID=system;Password=Meixuying;Data Source=D:\\app\\caokewen\\oradata\\orc\\SYSTEM01.DBF;Persist Security Info=true");
m_pConnection->Open(strConnect,"system","Meixuying",adModeUnknown);
//m_pConnection->Open("Provider=OraOLEDB.Oracle.1;Password=Meixuying;User ID=system;Data Source=orc;Persist Security Info=false","","",adModeUnknown); m_pConnection->ConnectionTimeout =5;//设置超时连接
}
catch(_com_error e)
{
// AfxMessageBox(TEXT("数据库连接出错!"));
// AfxMessageBox(e.Description()); CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}连接数据库失败!错误信息:无效的指针,各位大神,帮帮小弟吧
{
AfxMessageBox( "ole 初始化错误 ");
return FALSE;
}
try//连接数据库
{
m_pConnection->ConnectionTimeout =5;//设置超时连接
m_pConnection.CreateInstance(__uuidof(Connection));
_bstr_t strConnect=_T("DSN=OraOLEDB.Oracle.1;User ID=system;Password=Meixuying;Data Source=D:\\app\\caokewen\\oradata\\orc\\SYSTEM01.DBF;Persist Security Info=true");
m_pConnection->Open(strConnect,"system","Meixuying",adModeUnknown);
//m_pConnection->Open("Provider=OraOLEDB.Oracle.1;Password=Meixuying;User ID=system;Data Source=orc;Persist Security Info=false","","",adModeUnknown); m_pConnection->ConnectionTimeout =5;//设置超时连接
}
catch(_com_error e)
{
// AfxMessageBox(TEXT("数据库连接出错!"));
// AfxMessageBox(e.Description()); CString errormessage;
errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);///显示错误信息
}连接数据库失败!错误信息:无效的指针,各位大神,帮帮小弟吧
这里返回是否失败了
if (FAILED(hr))
{
_com_error e(hr);
AfxMessageBox(e.ErrorMessage());
return;
}
m_pConnection->ConnectionTimeout =5;//设置超时连接
m_pConnection.CreateInstance(__uuidof(Connection));换成
HRESULT hr =m_pConnection.CreateInstance(__uuidof(Connection));
m_pConnection->ConnectionTimeout =5;//设置超时连接还有,看看hr的返回值是否为0!
if ( !AfxOleInit() )
{
AfxMessageBox("初始化COM时失败!");
return FALSE;
}
try
{
HRESULT ht = S_OK; ht = pConn.CreateInstance(__uuidof( Connection ) );
if (FAILED(ht))
{
GetErrMsg(pConn,"建立ADO实例时错误:");
return FALSE;
}
else
m_adostate = 0; }catch(_com_error e)
{
CString cs;
cs.Format("建立ADO实例时出错:%s",e.Description());
AfxMessageBox(cs);
return FALSE;
}
Debug ERROR!
Program:e:\program\oracle\Debug\oracle.exe
this application has requested the runtime to terminate it in an unusual way .
please contact the applictation's support team for more information.
(Press Retry to debug the application)
最好是成功创建后进行下一步的操作:
if (SUCCESSED(hr))
{
........
}
"Data Source=MyOracleDB;" & _
"User Id=myUsername;" & _
"Password=myPassword;"或者:
oConn.Open "Driver={Microsoft ODBC for Oracle};" & _
"Server=OracleServer.world;" & _
"Uid=myUsername;" & _
"Pwd=myPassword;"