Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server 2012 querying Access 2007 data using OPENROWSET error

I would like to query data in Management Studio from a Microsoft Access 2007 database located on the same machine as my SQL Server 2012 instance. I do NOT want to use a linked server to do this as different Access databases can be chosen by the user. I am following the directions found on technet and other sources I have read said to use OPENROWSET as the proper way to do what I want, but when I execute this in Management Studio...

SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'C:\Users\oliver.klosoff\Desktop\New folder\41000-13-0085 Consolidated Killers LLC.mdb'; 'admin';'',tblTtlHrsFringes);

...I get the error below:

Msg 7302, Level 16, State 1, Line 1 Cannot create an instance of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".

The database does not have a password set for the admin user, and the admin user has permissions to read this table. Access 2007 32bit is installed on the machine, which is 64 bit, as well as the SQL Server instance. I believe that SQL Server can access the database file because when I get 1 when I execute this:

DECLARE @out INT
EXEC master.dbo.xp_fileexist 'C:\Users\oliver.klosoff\Desktop\New folder\41000-13-0085    Consolidated Killers LLC.mdb', @out OUTPUT
SELECT @out`

Is there a way to do what I am trying to accomplish?

like image 563
RoastBeast Avatar asked Oct 20 '22 15:10

RoastBeast


2 Answers

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:

ProviderOptions.png

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

OldPermissions.png

Once I granted myself Modify permissions on that folder

NewPermissions.png

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:

MyQuery.png

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.

like image 57
Gord Thompson Avatar answered Nov 15 '22 06:11

Gord Thompson


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;
like image 24
Muhannad Avatar answered Nov 15 '22 05:11

Muhannad