首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

提示unhandled exception in 222.exe (NTDLL.DLL);0xc0000005;Access Violation解决办法

2012-06-01 
提示unhandled exception in 222.exe (NTDLL.DLL);0xc0000005Access ViolationC/C++ codeCDatabase m_dat

提示unhandled exception in 222.exe (NTDLL.DLL);0xc0000005;Access Violation

C/C++ code
CDatabase m_database;    CString username;    CString password;    CString id;    m_database.Open(NULL,FALSE,FALSE,_T("ODBC;Dsn=student;server=localhost;uid=;pwd="));    CString strSQL;      strSQL.Format ("select * from  user_pass where username='%s'and password='%s' and id='%s' ",m_username,m_password,m_id);    int len = m_ListTeacher.GetHeaderCtrl()->GetItemCount();    try{    m_pSet->MoveFirst();    int nItem=m_ListTeacher.GetItemCount ();        while (!m_pSet->IsEOF())    {        username=m_pSet->m_username1;        password=m_pSet->m_password1;        id=m_pSet->m_id1;        m_ListTeacher.InsertItem(nItem,"");        m_ListTeacher.SetItemText(nItem,2,username);        m_ListTeacher.SetItemText(nItem,1,password);        m_ListTeacher.SetItemText(nItem,0,id);        m_pSet->MoveNext();        nItem ++;    }    }    catch(_com_error e) {  AfxMessageBox("表中存在记录为空!");  return; } m_pSet->Close();//关闭记录       }5void CMy222Dlg::OnButton2() {    // TODO: Add your control notification handler code here    CDatabase m_database;    CLoginSet* m_recordset=new CLoginSet (&m_database);    CString strSQL;    UpdateData(TRUE);    strSQL.Format ("select * from  user_pass where username='%s'and password='%s' ",m_username,m_password);    m_recordset->Open (AFX_DB_USE_DEFAULT_TYPE,strSQL);    if(m_recordset->GetRecordCount()==0)        MessageBox("密码错误",NULL,MB_OK);    else        MessageBox("登陆成功",NULL,MB_OK);

大家看看错在哪?标题的意思是? 本人新手刚接触数据库不久
求人心热解答

[解决办法]
异常捕获改成这样试试。
C/C++ code
try{//你的数据库代码代码}catch (_com_error& e){CString strMsg;strMsg.Format(_T("错误描述:%s\n错误消息%s",         (LPCTSTR)e.Description(),        (LPCTSTR)e.ErrorMessage());AfxMessageBox(strMsg);}catch(CException* pEx){pEx->ReportError();pEx->Delete();}
[解决办法]
应该是使用了没经过初始化的指针,访问到了系统内核了。

热点排行