代码如下
void CBnnnnDlg::OnButton1() 
{
// TODO: Add your control notification handler code here
CoInitialize(NULL);
_ConnectionPtr pConn(__uuidof(Connection));
_RecordsetPtr pRst(__uuidof(Recordset)); pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False";

pConn->Open("","","",adConnectUnspecified); pRst=pConn->Execute("select * from student",NULL,adCmdText); while (!pRst->adoEOF)
{
((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("names"));
pRst->MoveNext();

}
pRst->Close();
pConn->Close();
pRst.Release();
pConn.Release();
CoUninitialize();}按下Button1提示Runtime Error! Program:d:\text\bnnnn\Debug\bnnnn.exe This application has requested the Runtime to terminate it in an unusual way. 
Please contact the application's support team for more information. 
我下断点调试,好像是
pConn->Open("","","",adConnectUnspecified);
这行出错了!!但是我不会改……

解决方案 »

  1.   

    //用这个试一试,呵呵
    m_pCon->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=XX.mdb","","",adModeUnknown);
      

  2.   

    我是这么用的
    pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False","","",adModeUnknown);不管用啊,还是那个提示~
      

  3.   

    这个提示是在我VC下调试时提示的~
    如果我运行DEBUG文件夹下的那个程序就没有这个提示,可以正常访问!
      

  4.   

    pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False","","",adModeUnknown); 
    最后参数adModeUnknown换为edCmdText或者adCmdUnknown试试!
      

  5.   

    在pConn->Open和pConn->Execute语句外围加上try...catch结构.
    获取数据库操作的异常信息
      

  6.   


    void CBnnnnDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    CoInitialize(NULL);
    _ConnectionPtr pConn(__uuidof(Connection));
    _RecordsetPtr pRst(__uuidof(Recordset)); //pConn->ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False";
    try
    {
    pConn->Open("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=学生.mdb;Persist Security Info=False","","",adModeUnknown);

    }
    catch(_com_error e)
    {
    CString errormessage;
    errormessage.Format("数据库连接失败!\r \n 错误信息:%s",e.ErrorMessage());
    AfxMessageBox(errormessage);
    }
    pRst=pConn->Execute("select * from student",NULL,adCmdText);
    while (!pRst->adoEOF)
    {
    ((CListBox*)GetDlgItem(IDC_LIST1))->AddString((_bstr_t)pRst->GetCollect("names"));
    pRst->MoveNext();

    }
    pRst->Close();
    pConn->Close();
    pRst.Release();
    pConn.Release();
    CoUninitialize();}
    加入了捕捉错误代码~但是提示的是“未指定的错误”~~晕~~
      

  7.   


    try{
    pConn->Open("","","",adConnectUnspecified); 
    }
    catch(_com_error& e)
    {
    CString strValue;
    strValue.Format(_T("%s"),(LPCTSTR)e.Description());
                    AfxMessagebox(strValue);
    }看看什么错误,有可能是找不到数据库文件,你应该在数据库文件路径哪里动态获取绝对路径