VC++ connect string for Excel 2002?

From: Joe Hotchkiss (nospam_at_baesystems.com)
Date: 05/25/04

  • Next message: Christine Imbeault: "search all word begin "an*""
    Date: Tue, 25 May 2004 19:16:54 +0100
    
    

    Sorry if this isn't the best place to ask this but there seemed to be several
    similar questions here that didn't quite solve my problem.

    Briefly, what connect string do I need to use to create an Excel spread***
    using the CDaoDatabase class in VC++ 6.0?

    I have an application developed in VC++ 6.0 on Windows NT 4 with Office 97.
    This program creates and writes data to an Excel spread*** using the connect
    string "Excel 5.0;" in code similar to that shown below. This works fine.

    Now I have users trying to run the program on Windows 2000 & Office 2000 and
    Windows XP & Office 2002 and it doesn't work.
    The error message is something like "Couldn't find Installable ISAM".
    According to
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/office97/html
    /output/F1/D2/S5A279.asp I should be using the connect string "Excel 97;"
    anyway. I changed the string to "Excel 97;" and (if I recall correctly) it
    then worked on Windows/Office 2000 but still doesn't work on XP.

    Now I find that according to
    http://msdn.microsoft.com/library/en-us/dao360/html/daproconnect.asp?frame=tru
    e and
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_M
    FC_CDaoTableDef.3a3a.SetConnect.asp I should be using "Excel 8.0;". OK, that
    still works with NT/97 but not with XP/2002 (I don't have a 2000 machine handy
    to test it on). None of these references mentions Excel 2000 far less 2002.

    This is driving me up the wall. The solution almost certainly requires just
    the change of a couple of characters in a string but I cannot find any
    statement of what is required. The code below has been slightly simplified
    but is pretty close to what I am now trying to do.

    #include <afxdao.h>
    ...
    const char* ConnectString[] = {
                    "Excel 10.0;", "Excel 8.0;", "Excel 5.0;",
                    "Excel 2003;", "Excel 2002;", "Excel 2000;", "Excel 97;",
                    NULL
                };
    const char* DatabaseType = ConnectString[0];
    int DatabaseTypeIdx = 0;
    char* LogFileName = "c:\\temp\\Logfile.xls";

    m_pLogDatabase = new CDaoDatabase();
    do {
        try {
            m_pLogDatabase->Open (m_LogFileName, false, false, DatabaseType);
        }
        catch (CDaoException *e) {
            ++DatabaseTypeIdx;
            DatabaseType = ConnectString[DatabaseTypeIdx];
        }
    } while (!m_pLogDatabase->IsOpen() && NULL != DatabaseType);

    if (!m_pLogDatabase->IsOpen()) {
        // Report error...
        delete m_pLogDatabase;
        m_pLogDatabase = NULL;
    }

    if (NULL != m_pLogDatabase) {
        // Write data...
    }

    --
    Regards,
    Joe Hotchkiss,
    http://joe.hotchkiss.com
    XXXXXXXXXXXXXXXXXXXXXXXXX
    X   joe.hotchkiss       X
    X   at baesystems.com   X
    XXXXXXXXXXXXXXXXXXXXXXXXX
    

  • Next message: Christine Imbeault: "search all word begin "an*""