Reputation: 1826
I want to import an Excel file into SQL Server but I face an error.
My code:
create table test
(
AccountNumber varchar(50),
AccountName varchar(50),
ParentAccountNumber varchar(50)
)
select *
into test
FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;HDR=YES',
'SELECT * FROM [Sheet1$]')
Error:
Msg 7302, Level 16, State 1, Line 10
Cannot create an instance of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
Note:
Upvotes: 0
Views: 3712
Reputation: 357
If you are not aware of writing scripts, you can do it by wizard itself.
Upvotes: 1
Reputation: 910
Try running the below code:
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
select * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=D:\testing.xls;HDR=YES',
'SELECT * FROM [Sheet1$]')
Make sure your excel sheet is closed when you are running this code.
Upvotes: 0
Reputation: 419
Try this after table creation,
INSERT INTO test (AccountNumber , AccountName , ParentAccountNumber)
SELECT *
FROM OPENROWSET ('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=D:\testing.xls;HDR=YES',
'SELECT * FROM [Sheet1$]');
Upvotes: 0