Database - Error: Failed to create instance of OLE DB provider "Microsoft.Ace.OLEDB.12.0" for linked server "(null)".

AccessDatabaseEngine_X64 (2012).exeOnce installed , ready to import data from Excel:

Enter the following code

SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=D:\S072003228DBS\食品销售数据\类别.XLSX',[类别$]);

Error 1:
SQLServer blocked access to STATEMENT 'OpenRowset/OpenDatasource' of component 'AdHocDistributedQueries' because this component has been shut down as part of this server's security configuration. System administrators can use . sp_configure enables 'AdHocDistributedQueries'.
insert image description here
Solution:

	-- 启用Ad Hoc Distributed Queries:
	exec sp_configure 'show advanced options',1
    reconfigure
    exec sp_configure 'Ad Hoc Distributed Queries',1
    reconfigure

Note : For safety, close Ad Hoc Distributed Queries after use

	-- 为了安全,使用完成后,关闭Ad Hoc Distributed Queries
	exec sp_configure 'Ad Hoc Distributed Queries',0
	reconfigure
	exec sp_configure 'show advanced options',0
	reconfigure

Error 2:
Failed to create an instance of OLE DB provider "Microsoft.Ace.OLEDB.12.0" for linked server "(null)".

Add the following code:

    --允许在进程中使用ACE.OLEDB.12
    EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
    --允许动态参数
    EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1

Then it can be successfully imported:
insert image description here

Guess you like

Origin blog.csdn.net/wxfighting/article/details/123882612