为什么我的程序在调试的时候经常出现这样的错误,"Unhandled exception in XXXX.exe (xxxxxx.dll) 0xc0000005 Access Violation",还导致系统死机!!详情是,我用DAO操作数据库的时候,当在视图类操作数据库的时候不会有问题,但是当在其他自定义的类或者在文档类里执行到相关的数据库操作语句时(我的数据库用Access),就会弹出这样的对话框
"Unhandled exception in XXXX.exe (Dao350.dll) 0xc0000005 Access Violation"我是VC新手,这个问题看了很多书都不能解决,请各位大侠帮帮忙好吗?万分火急!!

解决方案 »

  1.   

    好象引入Dao类时不是标准操作或者是某一个和数据库关联的控件删除后而关联变量没有删除.
    最好把相关的代码贴出来.
      

  2.   

    谢谢!!
    相关代码如下
    问题出现在调用BOOL IsExistentTable(CDaoDatabase *pDatabase, CString strTableName)函数中的“pDatabase->GetTableDefInfo(strTableName, tableInfo); ”时候出现!!在视图类中调用不会出现问题!!
    再次谢谢!!
    /////////////////////////////////////////////////////
    构造函数初始化数据库指针
    CRead::CRead()
    {
    m_bWriten=FALSE;
    Reading_error=0;
    sequence=0;
    m_hCom=theApp.m_hCom;
    m_pDatabase= new CDaoDatabase; 
    m_pTableDef= new CDaoTableDef(m_pDatabase); 
    char path[50];
        GetCurrentDirectory(50,path);
    strcat(path,"\\");
    m_strDatabaseName=_T(path);
    m_strDatabaseName+=_T("Meters.mdb");//得到数据库文件的路径
    if(openDatabase(&m_pDatabase,m_strDatabaseName,TRUE)!=1)
    {
    AfxMessageBox("数据库打开失败!");
    return;
    }
    }
    调用语句:
    void CRead::ReadMeter(int tk,short Tn)
    {
    char mtrID[4];
    itoa(Tn,mtrID,10);
    BYTE Tp;
    Tp=theApp.mtr[tk].m_nType;
    switch(Tp)
    {
    case 0://EDMI表
    m_strTableName="EDMI3_";
    m_strTableName+=mtrID;
    if(!IsExistentTable(m_pDatabase,m_strTableName))
    {
    if(!CreateNewTable(1,m_strTableName))
    {
    AfxMessageBox("动态创建数据表失败");
    return;
    }
    }
    hx3_Read(tk,Tn);
    break;
    case 1:
    m_strTableName="EDMI6_";
    m_strTableName+=mtrID;
    if(!IsExistentTable(m_pDatabase,m_strTableName))
    {
    if(!CreateNewTable(1,m_strTableName))
    {
    AfxMessageBox("动态创建数据表失败");
    return;
    }
    }
    hx6_Read(tk,Tn);
    break;
             default:
    break;
    }
    }
    调用的两个数据库操作函数:
    BOOL IsExistentTable(CDaoDatabase *pDatabase, CString strTableName)
    {
    if (pDatabase == NULL)
    return FALSE;
    BOOL bDuplicateTableName = TRUE;
    CDaoTableDefInfo tableInfo; // only needed for the call
    TRY
    { // this call will throw an exception if there is no
    // table by the specified name--test for duplication
    pDatabase->GetTableDefInfo(strTableName, tableInfo);
    }
    CATCH (CDaoException, e)
    {
    // if this is an 'Item not found' exception, do something 
    if (e->m_pErrorInfo->m_lErrorCode == 3265)
    bDuplicateTableName = FALSE;
    }
    AND_CATCH (CMemoryException, e)
    {
    // do nothing
    ;
    }
    END_CATCH return bDuplicateTableName;
    }int openDatabase(CDaoDatabase **ppDatabase, CString fileName,BOOL bReportNoOpen /* = TRUE */)
    {
    int nReturnCode = 1;
    if (*ppDatabase != NULL)
    {
    if ((*ppDatabase)->IsOpen())
    closeDatabase(ppDatabase);
    delete *ppDatabase;
    }
    // construct new database
    *ppDatabase = new CDaoDatabase;

    if (ppDatabase == NULL)
    return -1; // fatal error // now open the database object with error checking
    try
    {
    (*ppDatabase)->Open(fileName);
    }
    catch (CDaoException *e)
    {
    if (e->m_pErrorInfo->m_lErrorCode == 3024)
    {
    if (bReportNoOpen)
    {
    // create a message to display
    CString message = _T("Couldn't open database--Exception: ");
    message += e->m_pErrorInfo->m_strDescription; // output status
    AfxMessageBox(message);
    }
    nReturnCode = 0;
    }
    else // other type of DAO exception--always report
    {
    // create a message to display
    CString message = _T("Couldn't open database--Exception: ");
    message += e->m_pErrorInfo->m_strDescription;
    AfxMessageBox(message);
    nReturnCode = -1;
    }
    e->Delete();
    delete *ppDatabase;
    *ppDatabase = NULL;
    }
    catch (CMemoryException *e)
    {
    // output status
    AfxMessageBox(_T("Failed to open database--Memory exception thrown."));
    e->Delete(); delete *ppDatabase;
    *ppDatabase = NULL;
    nReturnCode = -1;
    } return nReturnCode;
    }
      

  3.   

    会不会是你没有引用那些Dll或者是LIB阿你看看DAO开发的东西不过如果不是特表要求的化你可以用ADO,那个要方便些
      

  4.   

    没有仔细看你的程序,但看异常的信息最可能的情况是:
    指针是空的。
    也就是pDatabase->GetTableDefInfo(strTableName, tableInfo)中的
    pDatabase是无效的指针。也可能参数是空的指针?你跟踪进去看看就应该知道了嘛
      

  5.   

    等会我看看,以前写过这么个dao类