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 2000 Forums
 SQL Server Development (2000)
 OPENROWSET and EXCEL

Author  Topic 

philkos
Starting Member

5 Posts

Posted - 2006-11-07 : 09:25:47

I having an excel file called TEST.XLS (in c:\ drive) which has 3 columns (c0,c1,c2) & 8 rows
c0 c1 c2
1 a A
2 b B
3 c C
4 d D
5 e E
6 f F
7 g G
8 h H

In sql server i have one table called TEST which has three columns
c0 char(10)
c1 char(10)
c2 char(10)


when i runnig the following query

select *
into TEST from openrowset('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\TEST.xls;HDR=YES',
'select * from [Sheet1$]')



i am getting error like this

Server: Msg 7399, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.Jet.OLEDB.4.0' reported an error.
[OLE/DB provider returned message: The Microsoft Jet database engine could not find the object 'Sheet1$'. Make sure the object exists and that you spell its name and the path name correctly.]
OLE DB error trace [OLE/DB Provider 'Microsoft.Jet.OLEDB.4.0' IColumnsInfo::GetColumnsInfo returned 0x80004005: ].

Version : Sql server 2000 & Excel 2002

Anybody having any idea why this error occuring?
thanks in advance...
Philkos

snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-11-07 : 12:47:43
That error message is confusing but most likely means that the file name is wrong (not the contents of the file). For you statement, the file TEST.xls must exist in the root of the C: drive on the SQL Server - note on the server NOT on your local computer if you are using a SQL Server that is not running locally.

Also note that you need to use INSERT ... SELECT if you are inserting into an existing table
insert Test
select *
from openrowset('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:\TEST.xls;HDR=YES',
'select * from [Sheet1$]')

Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-11-07 : 12:52:04
Emphasize: THE PATH TO THE FILE IS RELATIVE THE SQL SERVER!
If the file is located on your machine, the path in the connection string must be "Database=\\YourComputerName\c$\tst.xls"
AND YOU MUST MAKE SURE THAT THE ACCOUNT USED FOR SQL SERVER HAS PERMISSION TO READ THE FILE


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -