CDatabase方法中
virtual BOOL OpenEx(
   LPCTSTR lpszConnectString,
   DWORD dwOptions = 0 
);
中的参数lpszConnectString应该付什么值,我试了很多比如:
cd.OpenEx("DSN=zxl; UID=zxl; PWD=zxl");
都不对。
那位能告诉我啊。谢谢了!

解决方案 »

  1.   

    ::Quote MSDN::Call this member function to initialize a newly constructed CDatabase object.virtual BOOL OpenEx(
       LPCTSTR lpszConnectString,
       DWORD dwOptions = 0 
    );
    Parameters
    lpszConnectString 
    Specifies an ODBC connection string. This includes the data source name as well as other optional information, such as a user ID and password. For example, "DSN=SQLServer_Source;UID=SA;PWD=abc123" is a possible connection string. Note that if you pass NULL for lpszConnectString, a Data Source dialog box will prompt the user to select a data source. 你要先建一个ODBC,然后获得连接字符串
      

  2.   

    // Embed a CDatabase object
    // in your document class
    CDatabase m_dbCust;// Connect the object to a 
    // read-only data source where
    // the ODBC connection dialog box
    // will always remain hidden
    m_dbCust.OpenEx( _T( "DSN=MYDATASOURCE;UID=JOES" ),
                     CDatabase::openReadOnly |
                     CDatabase::noOdbcDialog );
      

  3.   

    谢谢,请不要从msdn上拷,我也有,我看了.不懂,所以才上来.
    可不可以举个比较实际的例子
    告诉我
    DSN(填什么)UID(填什么)PWD(填什么)
    十分感谢了.
      

  4.   

    你写的前半部分是对的,不过OpenEx需要两个参数
    cd.OpenEx("DSN=zxl; UID=zxl; PWD=zxl", CDatabase::noOdbcDialog);
    其中DSN是ODBC名称,不知道你建了ODBC没有,UID是数据库用户名,PWD是UID的密码。
      

  5.   

    CString strConnect;
     strConnect.Format("DSN=lhwy;");
     if(!m_DB.OpenEx(strConnect,CDatabase::useCursorLib))
         {
         AfxMessageBox("Unable to Connect to the Specified Data Source");
         return FALSE ;
         }
    没有设置UID,PWD
      

  6.   

    谢谢你们,虽然问题还没解决,不过我也学会不少东西了,可能不是OpenEx(...)
    的原因吧,因为我写的跟你们说的一样.
    谢谢,给分了.