本帖最后由 zyq5945 于 2011-02-23 09:06:00 编辑

解决方案 »

  1.   

    依然捕捉异常
    catch(_com_error e) 

    AfxMessageBox(e.Description()); 
    }
      

  2.   

    程序执行到Execute() 就中断了
      

  3.   

    打印你的SQL语句,看是否在数据库access中执行正确.
      

  4.   

    用下面的catch可以抓到数据库服务器的错误消息
    /C++catch(const _com_error& e)
    {
    CString sBuff = GetProviderError(m_pConnection);
    if(sBuff.IsEmpty())
    {
    sBuff=GetComError(e);
    } AfxMessageBox(sBuff);
    }
    CString GetProviderError(_ConnectionPtr pConnection)
    {
    CString sErrors;
    if(pConnection != NULL)
    {
    ADODB::ErrorsPtr ptrErrors = pConnection->Errors;
    long lCount = ptrErrors->Count;
    ADODB::ErrorPtr ptrError = NULL;
    CString sError;
    for(long n = 0; n < lCount; n++)
    {
    ptrError = ptrErrors->GetItem(n);
    sError.Format(
    _T("%s\nState: %s, Native: %d, Source: %s"),
    (LPCTSTR)ptrError->Description,
    (LPCTSTR)ptrError->SQLState,
    ptrError->NativeError,
    (LPCTSTR)ptrError->Source
    );
    sErrors += sError + TEXT("\n\n");
    }
    } if(!sErrors.IsEmpty())
    sErrors = sErrors.Left(sErrors.GetLength()-2); return sErrors;
    }CString GetComError(const _com_error& e)
    {
    CString sMsg;
    sMsg.Format(
    _T("HRESULT: 0x%08lx; Error: %s"),
    e.Error(),
    e.ErrorMessage()
    ); if(e.ErrorInfo())
    {
    sMsg += TEXT("\nSource: ") + CString((LPCTSTR)e.Source()) +
    TEXT("; Description: ") + CString((LPCTSTR)e.Description());
    } return sMsg;
    }
      

  5.   

    我在access执行 :INSERT INTO action (user_Id,user_begintime,user_Dstairname, user_Pstairname) VALUES (3 ,'121', 'wer', 'xiaojiji');
    执行成功的。
    但是在代码里还是报错的:
    /C++strSql.Format("INSERT INTO action (user_Id,user_begintime,user_Dstairname, user_Pstairname) VALUES (3 ,'121', 'wer', 'xiaojiji');");
    m_pConnection->Execute((_bstr_t)strSql,NULL,adCmdText);
      

  6.   

    我在对ACCESS表  插入新的数据行时  程序中断报错。提示是msado15.tli 文件里一个未处理的异常,具体中断位置看我的提问。
      

  7.   

    在执行m_pConnection->Execute((_bstr_t)strSql,NULL,adCmdText); 的时候程序中断的,上面应该放哪? 放这句后面?中断后不执行的。
      

  8.   

    格式我也改不了
    user_begintime是时间格式的字段吗?是的话插入的字符串格式“YYYY-mm-DD HH:MM:SS” 
      

  9.   

    我是真的无语了~   VS2003 C++ 有规定 access 表名不能用action  和 text 的?  
    我实在是找不到这两个表 和 users表有什么区别了。抱着尝试下的心态 把action表名改成了user,竟然不报错了,我试了很多表名,就action 和 text 会报错。 真是无语,还正好两个都让我碰到了。悲剧的。这是我编译环境的问题?还是就这么规定的? 我用的环境是VS2003 MFC C++  access用的是2003版  系统:深度纯净版XP
    载入:#import "c:\program files\common files\system\ado\msado15.dll" no_namespace rename("EOF","adoEOF")
    初始化:AfxOleInit();
    接着就是代码了。  
     高兴的去尝试下,我也不知道是不是就我有这个问题。 这个问题从昨天搞到现在了,太悲剧了。
      

  10.   

    你把action和text 用[action]  [text]代替试试还报错不
      

  11.   

    依然捕捉异常
    catch(_com_error e)  
    {  
    AfxMessageBox(e.Description());