SQL Server 2012 querying Access 2007 data using OPENROWSET error

亡梦爱人 提交于 2019-11-27 15:20:18
Gord Thompson

Finally, after several unsuccessful attempts to have SQL Server "talk to" an Access database – either as a "Linked Server" in SSMS or via OPENROWSET() in T-SQL – I found this blog post that offered the following three (3) suggestions.

Tweak #1: OLE DB Provider settings

The OLE DB Provider for ACE (or Jet) must have the "Dynamic parameter" and "Allow inprocess" options enabled. In SSMS, open the

Server Objects > Linked Servers >Providers

branch, right-click "Microsoft.ACE.OLEDB.12.0" (or "Microsoft.Jet.OLEDB.4.0"), choose "Properties", and ensure that those options are selected:

Tweak #2: Temp folder permissions

This is the one that was stumping me.

Apparently SQL Server needs to write information into a temporary file while running an OLE DB query against an Access database. Because SQL Server is running as a service it uses the %TEMP% folder of the account under which the service is running.

If the SQL Server service is running under the built-in "Network Service" account then the temp folder is

%SystemRoot%\ServiceProfiles\NetworkService\AppData\Local\Temp

and if it is running under the built-in "Local Service" account then the temp folder is

%SystemRoot%\ServiceProfiles\LocalService\AppData\Local\Temp

My problem was that SSMS was running under my account (not NETWORK SERVICE) so I only had Read access to the Temp folder

Once I granted myself Modify permissions on that folder

and enabled OPENROWSET queries as documented in another question here, namely ...

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO

... my query worked fine:

Tweak #3: memory_to_reserve

Although I didn't need to use it in my case, the aforementioned blog also claims that adjusting the "-g memory_to_reserve" startup parameter for the SQL Server service can also help avoid similar errors. To do that:

  • launch SQL Server Configuration Manager
  • right-click the SQL Server service ("SQL Server Services" tab) and choose "Properties"
  • on the "Advanced" tab, prepend -g512; to the "Startup Parameters" setting
  • restart the SQL Server service

For more details on the "memory_to_reserve" setting see the MSDN article here.

Muhannad

This should work

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

USE [DatabaseName]

GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

SELECT *  FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0','Data Source="C:\Employees.accdb"')...tblEMPS;

Assuming you have the 'Northwind' sample installed (and in folder mentioned below), will the following run?

SELECT CustomerID, CompanyName
   FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
      'C:\Program Files\Microsoft Office\OFFICE11\SAMPLES\Northwind.mdb';
      'admin';'',Customers);
GO

Unfortunately I have not reinstalled SQL Server since my last reimage

Adam

Microsoft.Jet.OLEDB.4.0 may not work now(in 2018). Need to download AccessDatabaseEngine_X64.exe or AccessDatabaseEngine.exe to SQL server and intall it. Then use Microsoft.ACE.OLEDB.12.0.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!