我用ADO连接数据库。已经添加了#import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","rsEOF")  语句,并且在DEBUG文件夹中也产生了msado15.tlh和msado15.tli文件。主程序类的InitInstance()中加入   
也加入了::CoInitialize(NULL);
但还是出现如下错误:error C2146: syntax error : missing ';' before identifier 'm_pConnection';
                 error C2501: '_ConnectionPtr' : missing storage-class or type specifiers;
                 error C2501: 'm_pConnection' : missing storage-class or type specifiers;
哪位能帮帮忙???谢谢了   

解决方案 »

  1.   

    代码:
    变量声明:protected:
    _ConnectionPtr m_pConnection;
    这是数据库连接的代码
    HRESULT hr;
    try
    {
    hr=m_pConnection.CreateInstance(__uuidof(Connection));//创建Connection对象 if(SUCCEEDED(hr))
    {
    m_pConnection->ConnectionString="File Name=my_data.udl";
    m_pConnection->ConnectionTimeout=3;//设置超时时间为3秒
    hr=m_pConnection->Open("","","",adConnectUnspecified);
    if(FAILED(hr))
    {
    AfxMessageBox("Open Fail!");
    return false;
    }
    }
    else
    {
    AfxMessageBox("Createinstance of Connection fail!");
    return TRUE;
    }
    }
    catch(_com_error e)   //捕捉异常
    {
    _bstr_t bstrSource(e.Source());
    _bstr_t bstrDescription(e.Description());
    AfxMessageBox(bstrSource+bstrDescription);
    return TRUE;
    }
      

  2.   

    C:\Program Files\Common Files\System\ado\msado15.dll这个文件你确认有吗?
      

  3.   

    如果这个DLL有的话,清理下工程,重建就应该可以了
      

  4.   

    你的问题我的同事也遇见过,你先把DEBUG文件、.clw, .aps, .ncb,.opt文件删除重新编译看看,如果再不行你把
    #import "C:\Program Files\Common Files\System\ado\msado15.dll" no_namespace rename("EOF","rsEOF")语句放到声明_ConnectionPtr m_pConnection; 的文件中去,有些机子总是出现这种莫明的问题
      

  5.   

    都试了还是不行
    C:\金洋\桌面\vc++考勤管理系统\汽车租赁管理系统\汽车租赁管理系统Dlg.cpp(187) : error C2065: 'm_pConnection' : undeclared identifier
    C:\金洋\桌面\vc++考勤管理系统\汽车租赁管理系统\汽车租赁管理系统Dlg.cpp(187) : error C2228: left of '.CreateInstance' must have class/struct/union type
    C:\金洋\桌面\vc++考勤管理系统\汽车租赁管理系统\汽车租赁管理系统Dlg.cpp(191) : error C2227: left of '->ConnectionString' must point to class/struct/union
    C:\金洋\桌面\vc++考勤管理系统\汽车租赁管理系统\汽车租赁管理系统Dlg.cpp(193) : error C2227: left of '->Open' must point to class/struct/union