Create Linked server with Excel 2007 worksheet in SQL Server 2005

Tuesday, April 14, 2009 |

I have written one article to create linked server with Access database but I seen in many forums that people mostly would like to use excel file and wants to import its data. However, there are many ways to import Excel data to SQL Server but Linked server gives you more freedom over data. Let us see how we can do this. Before you start doing this, I would like you to create one excel 2007 file named “Dept” and put it in C: drive.

See my previous article for linked server with Access at

There will be two column in your excel 2007 file with following data in Sheet1

Department Description
MIS IT department
Acct Account Department
Chem Chemist Department

Now let us move to SQL server and make linked server.

EXECUTE sp_addlinkedserver

@server = 'DeptExcel',

@srvproduct = 'ACE 12.0',

@provider = 'Microsoft.ACE.OLEDB.12.0',

@datasrc = 'C:\Dept.xlsx',

@provstr = 'Excel 12.0'


--excel's credential if any

EXEC sp_addlinkedsrvlogin 'DeptExcel', 'false'


--list all tables from excel file

exec sp_tables_ex 'DeptExcel'


--see table in sheet1

SELECT * FROM [DeptExcel]...sheet1$


--create table in SQL and imports data

select * into tempTable FROM [DeptExcel]...sheet1$


--check your SQL table

select * from tempTable

Reference: Ritesh Shah
Note: Microsoft Books online is a default reference of all articles but examples and explanations prepared by Ritesh Shah, founder of


Anonymous said...

I get this error when I run exec sp_tables_ex 'DeptExcel'. I have already run AccessDatabaseEngine.exe:

Msg 7399, Level 16, State 1, Procedure sp_tables_ex, Line 41
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "DeptExcel" reported an error. Access denied.
Msg 7301, Level 16, State 2, Procedure sp_tables_ex, Line 41
Cannot obtain the required interface ("IID_IDBSchemaRowset") from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "DeptExcel".

Ritesh Shah said...

do you have proper permission on the file you are using? seems like either permission issue or file is open somewhere