我尝试使用以下查询将sql结果导出到Excel:
INSERT INTO OPENROWSET
('Microsoft.Jet.OLEDB.4.0','Excel 8.0;Database=c:\Test.xls;','SELECT client_name, Client_number FROM dbo.Client')
select * from dbo.client
但是我收到了这个错误:
Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.Jet.OLEDB.4.0" has not been registered.
在我搜索了解决方法并下载了2010 Microsoft Office System文件“Access Database Engine 2010 Redistributable”之后,当我运行上面的查询时,它仍然给出了同样的错误。我将提供商的名称更改为“Microsoft.ACE.OLEDB.12.0”并再次运行以下查询:
INSERT INTO OPENROWSET
('Microsoft.ACE.OLEDB.12.0',
'Excel 8.0;Database=c:\Test.xls;','SELECT client_name, Client_number FROM dbo.Client')
select * from dbo.client
它仍然给我这个错误:
Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered.
有人能告诉我这里发生了什么事吗?
总结一下:
为了使用OPENROWSET从/向x64 SQL Server导出/导入excel文件,您应该在服务器上而不是在工作站上安装Access Database Engine 2010 Redistributable。在您的服务器PC上成功安装此x64位驱动程序之前,您将收到错误消息
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered
尝试在您的OPENROWSET查询中使用此提供程序时
这适用于16.0或12.0,如下所示。以管理员身份打开SSMS,否则无法正常工作。
跑
EXEC sp_MSset_oledb_prop
应该有Microsoft.ACE.OLEDB.16.0。如果上面结果中的AllowInProcess和DynamicParameters不是1,则运行。
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.16.0'
, N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.16.0'
, N'DynamicParameters', 1
GO
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
然后尝试:(确保电子表格已关闭!)
INSERT INTO OPENROWSET
('Microsoft.ACE.OLEDB.16.0',
'Excel 12.0;Database=c:\test.xls;','SELECT Column1 FROM [ExcelSheet$]')
select Column1 from dbo.SQLTable
Microsoft.ACE.OLEDB.16.0可以从https://www.microsoft.com/en-us/download/details.aspx?id=54920获得
以上也适用于Microsoft.ACE.OLEDB.12.0
INSERT INTO OPENROWSET
('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=c:\test.xls;','SELECT Column1 FROM [ExcelSheet$]')
select Column1 from dbo.SQLTable
在这种情况下
需要https://www.microsoft.com/en-ca/download/details.aspx?id=13255。
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
您可以使用上面的Excel 8.0替换Excel 12.0。