2017-10-17 6 views
0

Je travaille sur un programme Foxpro 9. J'ai une fonction pour me connecter à Excel et ramener les informations de la colonne. En cours d'exécution dans Foxpro, cela fonctionne comme prévu. Cependant, lors de l'exécution d'un exécutable intégré, une boîte de dialogue Windows «Sélectionner la source de données» s'affiche et propose des options de source de données Fichier ou Machine. Choisir le bon ne fonctionne pas non plus, mais en tout cas je ne veux pas le dialogue.Foxpro ne parvient pas à se connecter à ODBC, montrant la boîte de dialogue

Ceci fonctionne en 64 bits Windows 8, mais j'ai également testé en 32 bits. Le fichier programme avec les fonctions Excel est intégré dans l'exécutable. Quelqu'un peut-il me dire pourquoi le programme construit fonctionne différemment?

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 

Répondre

2

résolu ce problème en mettant

SQLSETPROP(0, "DispLogin", 3) 

avant connecté.

+0

J'utiliserais aussi OLEDB sur ODBC. https://www.microsoft.com/en-us/download/details.aspx?id=14839 –