已完成一个单机版的管理系统开发并投入使用,现在客户要求做成网络版.
开发工具: VC6.0
使用类库: CDaoDatabase, CDaoRecordset
数据库类型: MS ACCESS单机版数据库安装在前台,客户要求在其他地方(如办公室)可以进入操作或查询.
可否使用CDaoDatabase.Open打开远程数据库,具体该如何配置?
是将数据库放在一个网站上还是设置一个局域网?

解决方案 »

  1.   

    在远程主机上配置下ODBC,这样就能远程访问mdb了
      

  2.   

    You must call this member function to initialize a newly constructed CDaoDatabase object that represents an existing database.virtual void Open(
       LPCTSTR lpszName,
       BOOL bExclusive = FALSE,
       BOOL bReadOnly = FALSE,
       LPCTSTR lpszConnect = _T(
       "" )
    );
    Parameters
    lpszName 
    A string expression that is the name of an existing Microsoft Jet (.MDB) database file. If the filename has an extension, it is required. If your network supports the uniform naming convention (UNC), you can also specify a network path, such as "\\\\MYSERVER\\MYSHARE\\MYDIR\\MYDB.MDB". (Double backslashes are required in string literals because "\" is the C++ escape character.) 
    Some considerations apply when using lpszName. If it: Refers to a database that is already open for exclusive access by another user, MFC throws an exception of type CDaoException. Trap that exception to let your user know that the database is unavailable. 
    Is an empty string ("") and lpszConnect is "ODBC;", a dialog box listing all registered ODBC data source names is displayed so the user can select a database. You should avoid direct connections to ODBC data sources; use an attached table instead. For information, see the article DAO External: Working with External Data Sources. 
    Otherwise does not refer to an existing database or valid ODBC data source name, MFC throws an exception of type CDaoException. 
    Note   For details about DAO error codes, see the DAOERR.H file. For related information, see the topic "Trappable Data Access Errors" in DAO Help.
    bExclusive 
    A Boolean value that is TRUE if the database is to be opened for exclusive (nonshared) access and FALSE if the database is to be opened for shared access. If you omit this argument, the database is opened for shared access. 
    bReadOnly 
    A Boolean value that is TRUE if the database is to be opened for read-only access and FALSE if the database is to be opened for read/write access. If you omit this argument, the database is opened for read/write access. All dependent recordsets inherit this attribute. 
    lpszConnect 
    A string expression used for opening the database. This string constitutes the ODBC connect arguments. You must supply the exclusive and read-only arguments to supply a source string. If the database is a Microsoft Jet database (.MDB), this string is empty (""). The syntax for the default value — _T("") — provides portability for Unicode as well as ANSI builds of your application. 
    Res
    Open associates the database with the underlying DAO object. You cannot use the database object to construct recordset, tabledef, or querydef objects until it is initialized. Open appends the database object to the associated workspace's Databases collection. Use the parameters as follows: If you are opening a Microsoft Jet (.MDB) database, use the lpszName parameter and pass an empty string for the lpszConnect parameter or pass a password string of the form ";PWD=password" if the database is password-protected (.MDB databases only). 
    If you are opening an ODBC data source, pass a valid ODBC connection string in lpszConnect and an empty string in lpszName. 
    For related information, see the topic "OpenDatabase Method" in DAO Help.Note   For better performance when accessing external databases, including ISAM databases and ODBC data sources, it is recommended that you attach external database tables to a Microsoft Jet engine database (.MDB) rather than connecting directly to the data source.
    It is possible for a connection attempt to time out if, for example, the DBMS host is unavailable. If the connection attempt fails, Open throws an exception of type CDaoException.The remaining res apply only to ODBC databases:If the database is an ODBC database and the parameters in your Open call do not contain enough information to make the connection, the ODBC driver opens a dialog box to obtain the necessary information from the user. When you call Open, your connection string, lpszConnect, is stored privately and is available by calling the GetConnect member function.If you wish, you can open your own dialog box before you call Open to get information from the user, such as a password, then add that information to the connection string you pass to Open. Or you might want to save the connection string you pass (perhaps in the Windows registry) so you can reuse it the next time your application calls Open on a CDaoDatabase object.You can also use the connection string for multiple levels of login authorization (each for a different CDaoDatabase object) or to convey other database-specific information. 
      

  3.   

    或者这样,
    CDaoDatabase*   pdb   =   new   CDaoDatabase();   
    pdb->Open("Z:\\mydata.mdb",FALSE,FALSE,_T(""));
    在一个局域网中,Z盘是网络映射盘,把其他机器上的一个盘或是一个文件夹映射成你本地的一个Z盘就好了