Click here to Skip to main content
15,887,821 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi guys,

I am trying to read from excel file in this way

SQL
SELECT *
FROM OPENROWSET(
      'Microsoft.ACE.OLEDB.12.0'
    , 'Excel 12.0;Database=C:\test.xls'
    , 'SELECT * FROM [sheet1$]'
);


all works fine. the file 'test.xls' is on local server

I have problems with files that are on remote server
how can I fix?



thanks in advance!
Posted
Comments
Herman<T>.Instance 22-Apr-14 10:47am    
C:\ points to local machine, not the remote server!
Member 10766684 22-Apr-14 11:02am    
i know

how can i link the remote server?

in this way..i have an error


SELECT *
FROM OPENROWSET(
'Microsoft.ACE.OLEDB.12.0'
, 'Excel 12.0;Database=\\remoteserver\file.xls'
, 'SELECT * FROM [sheet1$]'
);
Herman<T>.Instance 22-Apr-14 14:48pm    
What error do you get?
Member 10766684 23-Apr-14 3:57am    
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. The provider did not give any information about the error.

I have configure this:

USE [master]
GO

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO

EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO


For MS Excel *.xls files use proper connection string[^].

For further information, please see: The Basics of Excel Data Import to SQL Server[^]
 
Share this answer
 
string excelConnString = String.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties="Excel 12.0";", filePath);

specify the filepath if your server name is testserver, -> \\testserver\excelltest.xlsx
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900