请问如何读取Access数据库的系统表内容?用CRecordset被它拒绝了:(

解决方案 »

  1.   

    只有你能在Access操作系统表,你才可以访问,否则就不行
      

  2.   

    In order to grant the Admin user the necessary priveleges to the MSysObjects table, you can perform the following steps. 1. Open Microsoft Access 
    2. From the Tools menu, select the Options menu option 
    3. On the View tab, click the System Objects checkbox 
    4. Click OK to save your changes 
    5. From the Tools menu, select the Security -> User and Group Permissions menu option 
    6. Click the Permissions tab 
    7. Select the Table entry in the Object Type combo box 
    8. Select the Admin userid in the User/Group Name listbox 
    9. In the Object Name listbox, select the MSysObjects entry 
    10. In the Permissions group box, check the Read Data check box another method
    Avoiding having to use MS Access to set database security--------------------------------------------------------------------------------
    Using the DAO SDK directly it is possible to overcome the security limitation present in the MFC wrapper implementation of DAO so avoiding the need to set security through MS Access menus 
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfcnotes_tn054.asp 
    Explains the concepts involved. It should be noted that as explained in 
    http://dbforums.com/showthread.php?threadid=329995 
    using the system.mdw file makes it easier to write programs that leave the database locked after the program exits. 
    The following modification to the demo seems to overcomes the “Record(s) cannot be read; no read permission on MSysObjects” problem without needing to change the security on the database though Access Menus. use header #include "AFXDAO.H" to use the DAO functions and classes below ************************************************************************ 
    In CAccessReportViewerDoc.cpp add function void SetSystemDB( CString & strSystemMDB ) 

    COleVariant varSystemDB( strSystemMDB, VT_BSTRT ); // Initialize DAO for MFC 
    AfxDaoInit( ); 
    DAODBEngine* pDBEngine = AfxDaoGetEngine( ); ASSERT( pDBEngine != NULL ); // Call put_SystemDB method to set the 
    // system database for DAO engine 
    DAO_CHECK( pDBEngine->put_SystemDB( varSystemDB.bstrVal ) ); 
    } and modify function BOOL CAccessReportViewerDoc::OnOpenDocument(LPCTSTR lpszPathName) 

    //modify this to point to your system.mdw 
    CString strSystemDB = 
    _T( "C:\\Documents and Settings\\John\\Application Data\\Microsoft\\Access\\System.mdw" ); static bool bSetSystemDB=false; 
    if(bSetSystemDB==false) 

    SetSystemDB( strSystemDB ); 
    bSetSystemDB=true; 
    } if (!CDocument::OnOpenDocument(lpszPathName)) 
    return FALSE; m_pAccessReports = new CAccessReports(lpszPathName, TRUE); return TRUE; 

    ********************************************************************************* In CAccessReportViewerDoc.cpp add and modify function 
    int CAccessReportViewerApp::ExitInstance() 

    // TODO: Add your specialized code here and/or call the base class //terminates the DAO database engine 
    AfxDaoTerm( ); 
    return CWinApp::ExitInstance(); 
      

  3.   

    你说的是DAO,用CRecordset是没办法吗?那如果用ODBC API可以吗?应该没有权限的问题吧?另外,我一直都是用CDatabase,请教它和DAO有什么优缺点?
      

  4.   

    I don't think you can do it with CRecordset.
    DAO is powerful, but CRecordset is more general.
    But they are all out of fashion now, ADO is recommended
      

  5.   

    哈哈那我用asp得了,那个我最熟!
    不过还是感谢楼上的同志,敬礼!