SQL Server 2012 querying Access 2007 data using OPENROWSET error

后端 未结 4 1443
一个人的身影
一个人的身影 2020-12-03 19:13

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 link

相关标签:
4条回答
  • 2020-12-03 19:50

    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;
    
    0 讨论(0)
  • 2020-12-03 19:55

    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.

    0 讨论(0)
  • 2020-12-03 20:08

    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

    0 讨论(0)
  • 2020-12-03 20:12

    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.

    0 讨论(0)
提交回复
热议问题