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
 Transact-SQL (2000)
 Linking to excel or text files from SQL Server

Author  Topic 

hog
Constraint Violating Yak Guru

284 Posts

Posted - 2006-11-09 : 07:07:19
I have tried this method to connect to an excel spreadsheet:


sp_addlinkedserver N'Excel', N'Jet 4.0',
N'Microsoft.Jet.OLEDB.4.0',
N'c:\myspreadsheet.xls', NULL, N'Excel 5.0'
GO
sp_addlinkedsrvlogin N'Excel', false, sa, N'ADMIN', NULL
GO

SELECT *
FROM EXCEL...sheet1
GO


And get this error:

Server: Msg 7314, Level 16, State 1, Line 1
OLE DB provider 'EXCEL' does not contain table 'sheet1'. The table either does not exist or the current user does not have permissions on that table.
OLE DB error trace [Non-interface error: OLE DB provider does not contain the table: ProviderName='EXCEL', TableName='sheet1'].

Can anyone point me to where I am going wrong please?

Thanks

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-11-09 : 08:06:06
From BOL:

quote:
In order to access data from an Excel spreadsheet, associate a range of cells with a name. A given named range can be accessed by using the name of the range as the table name. The following query can be used to access a named range called SalesData using the linked server set up as above.

SELECT *
FROM EXCEL...SalesData
GO




Also try using OPENQUERY().

Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

KenW
Constraint Violating Yak Guru

391 Posts

Posted - 2006-11-09 : 16:22:25
quote:


sp_addlinkedserver N'Excel', N'Jet 4.0',
N'Microsoft.Jet.OLEDB.4.0',
N'c:\myspreadsheet.xls', NULL, N'Excel 5.0'




Also, is the spreadsheet actually on the server's c:\ drive? If it's not, you need to remember that the account that the SQL Server service is running under has to have access rights to the client machine, and that you need to include the path to the client machine, as in "\\ClientPC\C$\myspreadsheet.xls".

Ken
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-11-09 : 20:02:34
Also try openrowset
http://sqlteam.com/forums/topic.asp?TOPIC_ID=49926

Madhivanan

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

- Advertisement -