Page 1 of 1 1
Topic Options
#197340 - 2010-01-11 02:28 PM Using ADO with Excel
Skatterbrainz Offline
Starting to like KiXtart

Registered: 2002-10-17
Posts: 172
Loc: Virginia, USA
I'm trying to figure out why a small bit of VBScript code works fine, while the same (essentially) KiXtart code is giving me an error. Here's the VBScript code...
 Code:
dsn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='c:\test.xls';Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'"
Set conn = CreateObject("ADODB.Connection")
Set cmd  = CreateObject("ADODB.Command")
Set rs   = CreateObject("ADODB.Recordset")
conn.Open dsn


My KiXtart translation...
 Code:
$infile = "c:\test.xls"
$dsn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+$infile+";Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'"
$conn = CreateObject("ADODB.Connection")
$cmd  = CreateObject("ADODB.Command")
$rs   = CreateObject("ADODB.Recordset")
$conn.Open($dsn)


The KiXtart code fails with error: -2147352567
"Format of the initialization string does not conform to the OLE DB specification"

Can someone see what I may be doing wrong?
_________________________
silence is golden, but duct tape is silver

Top
#197341 - 2010-01-11 02:43 PM Re: Using ADO with Excel [Re: Skatterbrainz]
Glenn Barnas Administrator Offline
KiX Supporter
*****

Registered: 2003-01-28
Posts: 4401
Loc: New Jersey
One thing that jumps out is that in the VB example, the source path is enclosed in single quotes, but in your Kix translation it is not. Try
 Code:
$dsn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source='" + $infile + "';Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'" 
Adding spaces around the "+" makes it a bit more readable as well.

Glenn
_________________________
Actually I am a Rocket Scientist! \:D

Top
#197342 - 2010-01-11 03:30 PM Re: Using ADO with Excel [Re: Glenn Barnas]
Skatterbrainz Offline
Starting to like KiXtart

Registered: 2002-10-17
Posts: 172
Loc: Virginia, USA
Tried that also. Same result. \:\(
_________________________
silence is golden, but duct tape is silver

Top
#197344 - 2010-01-11 05:05 PM Re: Using ADO with Excel [Re: Skatterbrainz]
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Here is one I made earlier for another post on the board. Might help.

 Code:
$=SetOption("WrapAtEOL","ON")

$adSchemaColumns=4
$adSchemaTables=20

$sWorkbook="D:\TEST.XLS"

$oConn=GetExcelConnection($sWorkbook,"TRUE")
If @ERROR "Cannot open workbook: ["+@ERROR+"] "+@SERROR+@CRLF Exit @ERROR EndIf

$oCmd=CreateObject("ADODB.Command") 
$oCmd.Activeconnection=$oConn 

$oRS=$oConn.OpenSchema($adSchemaColumns)

@CRLF+"Validating workbook (sheet names, range names, column headers)..."+@CRLF
While Not $oRS.EOF
	$sTable = $oRS.Fields("table_name").Value
	$sColumn = $oRS.Fields("column_name").Value
	Chr(9)+"'"+$sColumn+"' is a column in "+IIf(Right($sTable,1)="$$","worksheet","range")+" "+$sTable+@CRLF
	$oRS.MoveNext
Loop

Function GetExcelConnection($sPath, Optional $bHeaders)
	Dim $sConn,$oConn
	$oConn=CreateObject('ADODB.Connection')
	If @ERROR Exit @ERROR EndIf
	$sConn='Provider=Microsoft.Jet.OLEDB.4.0;'
		+ 'Data Source='+$sPath+';'
		+ 'Extended Properties="Excel 8.0;HDR='
		+ IIf($bHeaders, 'Yes', 'No')+'"'
	$oConn.Open($sConn)
	$GetExcelConnection=$oConn

	Exit @ERROR
EndFunction

Top
Page 1 of 1 1


Moderator:  Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 739 anonymous users online.
Newest Members
M_Moore, BeeEm, min_seow, Audio, Hoschi
17883 Registered Users

Generated in 0.051 seconds in which 0.023 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org