Foxpro无法连接到ODBC,显示对话框

时间:2017-10-17 16:31:37

标签: foxpro

我正在开发Foxpro 9程序。我有一个连接到Excel并返回列信息的功能。在Foxpro中运行,这可以按预期工作。但是,运行构建的可执行文件时,会显示Windows“选择数据源”对话框,提供“文件”或“机器”数据源选项。选择正确的一个也不起作用,但无论如何我不想要对话。

这是在64位Windows 8中运行,但我也测试了32位。具有Excel功能的程序文件内置于可执行文件中。谁能告诉我为什么构建的程序运行方式不同?

RELEASE aCols
DIMENSION aCols(1)
AWorkSheetColumns(@aCols, m.tmpFile, m.tmpSheet, "DSN=Microsoft Excel Driver")

**********************************
FUNCTION AWorkSheetColumns(taArray, tcXLSFile, tcSheet, tnDSN)
**********************************
**********************************
* PARAMETER Information
* taArray := an array sent in by reference to fill with the specified worksheet's column information
* tcXLSFile := a string specifying an excel file (*.xls, *.xlsx, *.xlsm, *.xlsb) on disk
* tcSheet := a string specifying the worksheet or table to use when retrieving column information
*
* RETURN Information
* returns numeric, the number of columns found in the worksheet/table
**********************************
LOCAL lnSQL, laErr[1], lnResult, lnReturn, lcSQLAlias, loExc
m.lnReturn = 0
IF !EMPTY(m.tnDSN)
    m.lnSQL = SQLSTRINGCONNECT(m.tnDSN+ ";" ;
        +"DBQ="+FULLPATH(m.tcXLSFile)+";")
ELSE
    m.lnSQL = SQLSTRINGCONNECT("Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" ;
        +"DBQ="+FULLPATH(m.tcXLSFile)+";")
ENDIF
*!* Alternate using DSN that comes with Office install (MSDASQL = OLEDB wrapper for ODBC)
*!*     m.lnSQL = SQLSTRINGCONNECT("Provider=MSDASQL.1;" ;
*!*         +"Persist Security Info=False;" ;
*!*         +"DSN=Excel Files;" ;
*!*         +"DBQ="+FULLPATH(m.tcXLSFile)+";" ;
*!*         +"DriverId=790;" ;
*!*         +"MaxBufferSize=2048;" ;
*!*         +"PageTimeout=5;")

*!* Try a few other drivers that may be on the user's machine
IF m.lnSQL < 0
    IF UPPER(ALLTRIM(JUSTEXT(m.tcXLSFile))) == "XLS" && can we try using the older driver?
        m.lnSQL = SQLSTRINGCONNECT("Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" ;
            + "DBQ="+FULLPATH(m.tcXLSFile)+";")
        IF m.lnSQL < 0
            m.lnSQL = SQLSTRINGCONNECT("Driver={Microsoft Excel Driver (*.xls)};" ;
                + "DBQ="+FULLPATH(m.tcXLSFile)+";")
        ENDIF
    ELSE
        m.lnSQL = SQLSTRINGCONNECT("Driver={Microsoft Excel Driver (*.xls, *.xlsx, *.xlsm, *.xlsb)};" ;
            + "DBQ="+FULLPATH(m.tcXLSFile)+";")
    ENDIF
    IF m.lnSQL < 0
        AERROR(m.laErr)
        ERROR m.laErr[2]
    ENDIF
ENDIF

m.lcSQLAlias = SYS(2015)
m.lnResult = SQLEXEC(m.lnSQL,[SELECT * FROM "] + m.tcSheet + [$" Where 1=0], m.lcSQLAlias)

IF m.lnSQL > 0
    SQLDISCONNECT(m.lnSQL)
ENDIF

IF m.lnResult < 0
    AERROR(m.laErr)
    ERROR m.laErr[2]
ENDIF

IF USED(m.lcSQLAlias)
    TRY
        m.lnReturn = AFIELDS(m.taArray, m.lcSQLAlias)
    CATCH TO m.loExc
        THROW
    FINALLY
        USE IN SELECT(m.lcSQLAlias)
    ENDTRY
ENDIF

RETURN m.lnReturn
ENDFUNC

1 个答案:

答案 0 :(得分:2)

通过设置

解决了此问题
thread

在我连接之前。