CDatabase::Open和OpenEx有什么不同之处。

解决方案 »

  1.   

    两个函数的具别在于参数方面:
    virtual BOOL Open(
       LPCTSTR lpszDSN,
       BOOL bExclusive = FALSE,
       BOOL bReadOnly = FALSE,
       LPCTSTR lpszConnect = _T("ODBC;"),
       BOOL bUseCursorLib = TRUE 
    );virtual BOOL OpenEx(
       LPCTSTR lpszConnectString,
       DWORD dwOptions = 0 
    ); dwOptions 
    A bitmask which specifies a combination of the following values. The default value is 0, meaning that the database will be opened as shared with write access, the ODBC Cursor Library DLL will not be loaded, and the ODBC connection dialog box will display only if there is not enough information to make the connection. 
    CDatabase::openExclusive   Not supported in this version of the class library. A data source is always opened as shared (not exclusive). Currently, an assertion fails if you specify this option. 
    CDatabase::openReadOnly   Open the data source as read-only. 
    CDatabase::useCursorLib   Load the ODBC Cursor Library DLL. The cursor library masks some functionality of the underlying ODBC driver, effectively preventing the use of dynasets (if the driver supports them). The only cursors supported if the cursor library is loaded are static snapshots and forward-only cursors. If you plan to create a recordset object directly from CRecordset without deriving from it, you should not load the cursor library. 
    CDatabase::noOdbcDialog   Do not display the ODBC connection dialog box, regardless of whether enough connection information is supplied. 
    CDatabase::forceOdbcDialog   Always display the ODBC connection dialog box. 可以看到Open函数的后几个参数在OpenEx里面整合到第二个参数了。Res
    Your database object must be initialized before you can use it to construct a recordset object.Note   Calling the OpenEx member function is the preferred way to connect to a data source and initialize your database object.微软推荐首选OpenEx 函数