连接数据库没问题,是没有通过DSN连接的,也没有什么错误,但执行到
m_pRecordset->Open((_bstr_t)bstrSQL,_variant_t((IDispatch*)m_PConnection),adOpenDynamic,adLockOptimistic,adCmdText); 就报错:无效指针
百思不得其解
请高手指点!!!

解决方案 »

  1.   

    正确连接了,源码是:CString strSql="select * from t_czy";

        BSTR  bstrSQL = strSql.AllocSysString();  ////////////////////////
    HRESULT hr;

    try
    {
    hr=m_PConnection.CreateInstance("ADODB.Connection");
    if(SUCCEEDED(hr))
       m_PConnection->Open("driver={SQL Server};Server=127.0.0.1;DATABASE=gomsdb;UID=sa;PWD=hhq","","",adModeUnknown);
            else
    exit(-1);
    }
    catch(_com_error e)
    {
    CString errormessage;
    errormessage.Format("连接数据库失败!\r\n错误信息:%s",e.ErrorMessage()); 
    AfxMessageBox(errormessage); }
    exit(-1);
    }执行时并没有报什么错误!!
      

  2.   

    不好意思,问题解决了,我没有初始化recodset指针。