Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Problem importing a XLS file

Author  Topic 

AK-85
Starting Member

6 Posts

Posted - 2010-03-31 : 15:40:33
Hi,
I have this problem with importing an XLS file into the database. I tried many variants but nothing worked. For example when I try to select the contents of the XLS like this:

SELECT CONVERT(xml, BulkColumn, 2) FROM 
OPENROWSET(Bulk 'C:\Files\Person.xls', SINGLE_BLOB) AS x;


I get the following error:

Msg 9403, Level 16, State 1, Line 1
XML parsing: line 0, character 0, unrecognized input signature


I tried also the following:

INSERT INTO Person
WITH (KEEPIDENTITY)
(id, name, sname, yob)
SELECT *
FROM OPENROWSET(BULK 'C:\Files\Person.xls', SINGLE_BLOB) AS x;


I get this error:

Msg 120, Level 15, State 1, Line 1
The select list for the INSERT statement contains fewer items than the insert list. The number of SELECT values must match the number of INSERT columns.


I try only with the SELECT without the INSERT like this:

SELECT *
FROM OPENROWSET(BULK 'C:\Files\Person.xls', SINGLE_BLOB) AS x;


and then I get a table with a single column named BulkColumn and with a single row (cell) which contains some hexadecimal number.

Any idea what's wrong?

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-03-31 : 16:54:50
See http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-03-31 : 18:27:36
If the SELECT without the INSERt returns one column, then you can insert one column into four columns. Your INSERT statement has 4 columns.

Or am I missing the point?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

AK-85
Starting Member

6 Posts

Posted - 2010-04-01 : 02:07:26
quote:
Originally posted by tkizer

If the SELECT without the INSERt returns one column, then you can insert one column into four columns. Your INSERT statement has 4 columns.

Or am I missing the point?



Yes, it returns exactly one column with one row (i.e. one cell) with some nonsense in it.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-04-01 : 02:12:19
It's because XLS files has a propritary format. You use BULK option with SINGLE_CLOB to read complete (bimary) file in one step.
Again, see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926 how to import data from Excel.



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

AK-85
Starting Member

6 Posts

Posted - 2010-04-01 : 02:41:58
quote:
Originally posted by Peso

It's because XLS files has a propritary format. You use BULK option with SINGLE_CLOB to read complete (bimary) file in one step.
Again, see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926 how to import data from Excel.



Thanks for the help! Out of the discussion I came up to this but it still doesn't work:

SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Files\Person.xls;HDR=YES',
'SELECT * FROM [Sheet1$]');


The error message that I get is this:

Msg 7308, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for
distributed queries because the provider is configured to run
in single-threaded apartment mode.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-04-01 : 06:19:17
quote:
Originally posted by AK-85

quote:
Originally posted by Peso

It's because XLS files has a propritary format. You use BULK option with SINGLE_CLOB to read complete (bimary) file in one step.
Again, see http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=49926 how to import data from Excel.



Thanks for the help! Out of the discussion I came up to this but it still doesn't work:

SELECT *
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\Files\Person.xls;HDR=YES',
'SELECT * FROM [Sheet1$]');


The error message that I get is this:

Msg 7308, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' cannot be used for
distributed queries because the provider is configured to run
in single-threaded apartment mode.



Are you using 64 bit version of OS?
The above method wont work on that
You may need to download this http://www.microsoft.com/downloads/details.aspx?FamilyID=000364db-5e8b-44a8-b9be-ca44d18b059b&displaylang=en

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

AK-85
Starting Member

6 Posts

Posted - 2010-04-01 : 06:34:32
Of course. Windows Server 2008 R2 ships only in 64bit version. What I found is that I have to configure OLDEB to work in multithreaded apartment (MTA) mode but I don't know how to do it.
Go to Top of Page

bpsintl
Posting Yak Master

132 Posts

Posted - 2011-06-17 : 04:01:23
I know this is an old post but I'm in this position too. Have you found out how to put OLEDB in multitheaded appartment mode?
Go to Top of Page
   

- Advertisement -