views:

1613

answers:

2

Hello - I'm running a SQL SELECT query through an ADO connection to an Excel 2007 workbook with the following code (using a custom version of VBScript)

dim ado, rs
set ado = CreateObject("ADODB.Connection")
ado.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=workbook.xlsx;Extended Properties=""Excel 12.0 Xml;HDR=YES;IMEX=1"";"
ado.open()
set rs = ado.execute("SELECT * FROM [sheet1$]")

which is straighforward. The problem is that any cell that has text longer than 255 characters is truncated; is there any way around this? Is there a property in the connection string that will support this or is it an option I need to change in the excel document itself? I have tried MSSQL's CAST() function but this just causes an error when executed.

Any help would be greatly appreciated.

A: 

Instead of trying to use CAST(), have you tried to use the CONVERT() function?

TheTXI
I get an "Undefined function" error when using CONVERT, just tried it
thegravytalker
@TheGravyTalker: Were you using Convert() correctly? Convert(varchar(500), FieldName)?
TheTXI
yep, just like that
thegravytalker
+1  A: 

I think you're running into a variant of a long-standing limitation in Excel's data access provider. See http://support.microsoft.com/default.aspx?scid=kb;EN-US;189897 for an example or google for thousands more.

Jamie Ide
following the info given in the kb article, I changed the corresponding value in the registration key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\12.0\Access Connectivity Engine\Engines\Excel but this failed to correct the problem; changing to jet 4 with the above fix did work.
thegravytalker