给的代码不完整。先确保你的m_pConn有没有调用CreateInstance创建
用下面代码看看_bstr_t strDsn,str_db_user,str_db_pwd;
_ConnectionPtr pConnection;
...
try{
pRecordset.CreateInstance("ADODB.RecordSet");
pConnection->Open(strDsn,str_db_user,str_db_pwd,adConnectUnspecified);
}
catch(_com_error e){
if(pConnection!=NULL && pConnection->State){
pConnection->Close();
}
pConnection=NULL;
}

解决方案 »

  1.   

    we need  use Errors from connection object. Following is the code
    example from MSDN..
    ///////////////////////////////////////////////////////////
    //                                                       //
    //      PrintProviderError Function                      //
    //                                                       //
    ///////////////////////////////////////////////////////////void PrintProviderError(_ConnectionPtr pConnection)
    {
        //Define Other Variables
        HRESULT  hr = S_OK;
        _bstr_t  strError;
        ErrorPtr  pErr = NULL;    try
        {
            // Enumerate Errors collection and display
            // properties of each Error object.
            long nCount = pConnection->Errors->Count;        // Collection ranges from 0 to nCount - 1.
            for(long i = 0; i < nCount; i++)
            {
                pErr = pConnection->Errors->GetItem(i);
                printf("Error #%d\n", pErr->Number);
                printf("\t %s\n",(LPCSTR)pErr->Description);
                printf("\t(Source: %s)\n",(LPCSTR)pErr->Source);
                printf("\t(SQL State: %s)\n",(LPCSTR)pErr->SQLState);
                printf("\t(NativeError: %d)\n",(LPCSTR)pErr->NativeError);
                if ((LPCSTR)pErr->GetHelpFile() == NULL)
                {
                    printf("\tNo Help file available\n");
                }
                else
                {
                    printf("\t(HelpFile: %s\n)" ,pErr->HelpFile);
                    printf("\t(HelpContext: %s\n)" , pErr->HelpContext);
                }
            }
        }
        catch(_com_error &e)
        {
            // Notify the user of errors if any.
            PrintComError(e);
        }
    }///////////////////////////////////////////////////////////
    //                                                       //
    //      PrintComError Function                           //
    //                                                       //
    ///////////////////////////////////////////////////////////void PrintComError(_com_error &e)
    {
       // Notify the user of errors if any.
       _bstr_t bstrSource(e.Source());
       _bstr_t bstrDescription(e.Description());
        
        // Print Com errors.
        
       printf("Error\n");
       printf("\tCode = %08lx\n", e.Error());
       printf("\tCode meaning = %s", e.ErrorMessage());
       printf("\tSource = %s\n", (LPCSTR) bstrSource);
       printf("\tDescription = %s\n", (LPCSTR) bstrDescription);
    }