0
我正在使用Foxpro 9程序。我有一個連接到Excel的功能,並帶回列信息。在Foxpro中運行,這可以按預期工作。但是,運行構建的可執行文件時,會顯示Windows的「選擇數據源」對話框,提供「文件」或「機器」數據源選項。選擇正確的一個也行不通,但無論如何我不想進行對話。Foxpro無法連接到ODBC,顯示對話框
這是運行在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
我也會在ODBC上使用OLEDB。 https://www.microsoft.com/en-us/download/details.aspx?id=14839 –