简体   繁体   English

使用OPENROWSET将SQL结果导出到Excel,但未注册提供程序

[英]Export SQL result to Excel by using OPENROWSET, but provider has not been registered

I tried to export the sql result to Excel by using below queries: 我试图通过使用以下查询将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

However I got this error: 但是我得到了这个错误:

Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.Jet.OLEDB.4.0" has not been registered.

After I searched about workaround and downloaded the 2010 Microsoft Office System file "Access Database Engine 2010 Redistributable", it still give me the same error when I run the query above. 在搜索解决方法并下载2010 Microsoft Office System文件“ Access Database Engine 2010可再发行文件”之后,当我运行上述查询时,它仍然给我同样的错误。 I changed the provider's name to "Microsoft.ACE.OLEDB.12.0" and run below queries again: 我将提供程序的名称更改为“ 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

It still give me this error: 它仍然给我这个错误:

Msg 7403, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered.

Can anyone tell me what's going on here please? 谁能告诉我这是怎么回事?

to summarize: 总结一下:

In order to use OPENROWSET for export/import excel files from/to x64 SQL Server you should install Access Database Engine 2010 Redistributable on your server, not on your workstation. 为了使用OPENROWSET从x64 SQL Server导出/导入Excel文件,您应该在服务器上而不是在工作站上安装Access Database Engine 2010 Redistributable。 Until you successfully install this x64 bit driver on your server pc you'll get the error 在服务器PC上成功安装此x64位驱动程序之前,您将得到错误

The OLE DB provider "Microsoft.ACE.OLEDB.12.0" has not been registered

while trying to use this provider in your OPENROWSET queries 尝试在OPENROWSET查询中使用此提供程序时

This works for 16.0 or 12.0 as follows.. Open SSMS as Administrator, it won't work otherwise. 它适用于16.0或12.0,如下所示。。以管理员身份打开SSMS,否则将无法正常工作。

Run

EXEC sp_MSset_oledb_prop

Microsoft.ACE.OLEDB.16.0 should be there. Microsoft.ACE.OLEDB.16.0应该在那里。 Run if AllowInProcess and DynamicParameters in results above are not 1. 如果上面结果中的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

Then try: (Make sure the spreadsheet is closed!) 然后尝试:(确保电子表格已关闭!)

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 can be obtained from https://www.microsoft.com/en-us/download/details.aspx?id=54920 可以从https://www.microsoft.com/zh-cn/download/details.aspx?id=54920获得Microsoft.ACE.OLEDB.16.0

The above also works with Microsoft.ACE.OLEDB.12.0 以上也适用于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 

In which case 在这种情况下

https://www.microsoft.com/en-ca/download/details.aspx?id=13255 is needed. 需要https://www.microsoft.com/zh-cn/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

You can replace Excel 12.0 with Excel 8.0 above. 您可以将Excel 12.0替换为上面的Excel 8.0。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM