0

我想将查询的结果行写入 Excel 文件:

INSERT into OPENROWSET('Microsoft.ACE.OLEDB.12.0', 
'Excel 12.0;Database=C:\temp\testing.xlsx;', 
'SELECT Id,CompanyName FROM [Sheet1$]') 
select Id,CompanyName   from tbl_Company

但是在运行此查询时会出现以下错误:

消息 7302,级别 16,状态 1,第 3 行无法为链接服务器“(null)”创建 OLE DB 提供程序“Microsoft.ACE.OLEDB.12.0”的实例。

在运行此代码之前做了什么:

1 - 我安装了“2007 Office System 驱动程序:数据连接组件”

2 - 为使用 Excel 执行的配置脚本:

 sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO

3 - 将 SQL Server 服务的登录帐户更改为本地帐户

4 - 将 Excel 文件夹的完全访问权限添加到本地帐户

5 - 重新启动 SQL 服务

但我的问题仍然存在

服务器:Windows Server 2008

服务器上未安装 MS Office

SQL Server 2014 64 位 SP1

4

1 回答 1

0

我有一个错误:

我应该运行这个配置脚本

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 

您还应该确保安装 64 位版本的 Access 数据库引擎(如果您的 sql 服务器是 64 位)。

于 2016-05-09T10:29:49.533 回答