使用Microsoft.ACE.OLEDB.12.0将数据从Excel导入SQL Server数据库

时间:2013-04-30 08:56:23

标签: sql-server excel oledb

我正在开发一个应用程序,我需要将数据从Excel导入MS SQL Server数据库。 我在MS SQL Server计算机和我的计算机上安装了Microsoft Access Database Engine 2010 Redistributable

像这样配置MS SQL Server:

USE [master]
GO
sp_configure 'show advanced options', 1
GO
RECONFIGURE WITH OverRide
GO
sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE WITH OverRide
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

在我的应用程序中,我正在使用:

SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=PathToMyExcelDoc', [Devices$])

当应用程序和SQL Server在同一台机器上时,它运行正常,但是当我在我的机器上运行应用程序并尝试将数据从Excel导入到远程SQL Server时,我收到以下错误:< / p>

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.
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".

1 个答案:

答案 0 :(得分:2)

我遇到了同样的问题,我首先将excel保存到服务器,然后在OPENROWSET中传递该路径,解决了这个问题。