Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Connect to OLEDB provider using ODBC
Message
From
17/02/2012 14:15:56
Joel Leach
Memorial Business Systems, Inc.
Tennessee, United States
 
General information
Forum:
Visual FoxPro
Category:
Client/server
Environment versions
Visual FoxPro:
VFP 9 SP2
Miscellaneous
Thread ID:
01535618
Message ID:
01535688
Views:
68
I am currently running on a 32-bit machine, but I have used Craig's code with Office 2010 on a 64-bit machine with no problems. My new code will be tested soon on a 64-bit machine as well. You can download drivers from http://www.microsoft.com/download/en/details.aspx?id=13255

>In my case the driver is somehow corrupted. I have to re-install it but I don't know from where. In other words, when I try to edit it using ODBC 32 version of the program, I got errors.
>
>Are you able to open and check this driver OK? What is your version of OS and Office?
>
>>>>You need 64 bit drivers.
>>>>
>>>I do have them, but the question is - will it work from VFP which is 32 bit application?
>>
>>I believe Office x64 will install both 32-bit and 64-bit drivers, but VFP can only use the 32-bit drivers. This is ok because the drivers work directly with the files. They are not automating Office.
>>
>>To resolve my issue, I added code to AppendXLSX.prg for using ADO to access the OLEDB driver when the first row contains data rather than column headings. Here is the new code:
>>
>>	TRY
>>		SELECT (m.tvWorkarea)
>>		
>>        **** New Code Start ****
>>	*JAL* Excel ODBC driver has a bug that assumes first row always contains column names
>>	*JAL* See http://support.microsoft.com/kb/288343
>>	*JAL* If first row contains data, you have to use OLEDB driver and ADO to read data
>>	If m.lcHeaderRow = "No"
>>		Local loConn as ADODB.Connection, loRS as ADODB.Recordset, loCursor as CursorAdapter
>>		
>>		loConn = CreateObject("ADODB.Connection")
>>		loConn.ConnectionString = [Provider=Microsoft.ACE.OLEDB.12.0;Data Source="] + m.tcXLSFile + [";Extended Properties="Excel 12.0;HDR=] + m.lcHeaderRow + [;";]
>>		loConn.Open()
>>		If loConn.State = 1	&& connection open
>>			loRS = CreateObject("ADODB.Recordset")
>>			loRS.ActiveConnection = loConn
>>			loCursor = CreateObject("CursorAdapter")
>>			loCursor.Alias = m.lcSQLAlias
>>			loCursor.DataSourceType = "ADO"
>>			loCursor.DataSource = loRS
>>	 		loCursor.SelectCmd = "SELECT " + m.tcExcelFieldList + " FROM [" + m.tcSheet + "] Where " + m.tcExcelWhereExpr
>>			If !loCursor.CursorFill()
>>				AError(laErr)
>>				ERROR m.laErr[2]
>>			EndIf 
>>		EndIf 
>>	Else 
>>            * Existing code to open ODBC connection ...
>>        EndIf
>>        **** New Code End ****
>>
>>	IF USED(m.lcSQLAlias)
>>         ...
>>
Joel Leach
Microsoft Certified Professional
Blog: http://www.joelleach.net
Previous
Reply
Map
View

Click here to load this message in the networking platform