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);///显示错误信息 
}连接数据库失败!错误信息:无效的指针,各位大神,帮帮小弟吧

解决方案 »

  1.   

    m_pConnection.CreateInstance(__uuidof(Connection));
    这里返回是否失败了
      

  2.   

    HRESULT hr = m_pConnection.CreateInstance(__uuidof(Connection));
    if (FAILED(hr))
    {
    _com_error e(hr);
    AfxMessageBox(e.ErrorMessage());
    return;
    }
      

  3.   

    要把这两句位置换一下:
    m_pConnection->ConnectionTimeout =5;//设置超时连接
    m_pConnection.CreateInstance(__uuidof(Connection));换成
    HRESULT hr =m_pConnection.CreateInstance(__uuidof(Connection));
    m_pConnection->ConnectionTimeout =5;//设置超时连接还有,看看hr的返回值是否为0!
      

  4.   


      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;
    }
      

  5.   

    对了还有个错误
    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)
      

  6.   

    "hr的值不为0 显示的是:操作成功完成,按照你说的做,错误信息是:未指定的错误"不为0,说明创建语句失败!进一步的操作没有任何意义!
    最好是成功创建后进行下一步的操作:
    if (SUCCESSED(hr))
    {
       ........
    }
      

  7.   

    更换连接字符串:oConn.Open "Provider=OraOLEDB.Oracle;" & _
              "Data Source=MyOracleDB;" & _ 
              "User Id=myUsername;" & _
              "Password=myPassword;"或者:
    oConn.Open "Driver={Microsoft ODBC for Oracle};" & _
              "Server=OracleServer.world;" & _
              "Uid=myUsername;" & _
              "Pwd=myPassword;"