Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
614 views
in Technique[技术] by (71.8m points)

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:Usersoliver.klosoffDesktopNew folder41000-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:Usersoliver.klosoffDesktopNew folder41000-13-0085    Consolidated Killers LLC.mdb', @out OUTPUT
SELECT @out`

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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%ServiceProfilesNetworkServiceAppDataLocalTemp

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

%SystemRoot%ServiceProfilesLocalServiceAppDataLocalTemp

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...