The OLE DB provider “Microsoft.ACE.OLEDB.12.0” for linked server “(null)”

后端 未结 19 1718
灰色年华
灰色年华 2020-12-02 17:27

I\'m trying to run the following statement but am receiving the error messages just below. I have researched answers to no end and none have worked for me. I\'m running Of

相关标签:
19条回答
  • 2020-12-02 17:48

    This is for my reference, as I encountered a variety of SQL error messages while trying to connect with provider. Other answers prescribe "try this, then this, then this". I appreciate the other answers, but I like to pair specific solutions with specific problems


    Error

    ...provider did not give information...Cannot initialize data source object...

    Error Numbers

    7399, 7303

    Error Detail

    Msg 7399, Level 16, State 1, Line 2 The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. 
      The provider did not give any information about the error. 
    Msg 7303, Level 16, State 1, Line 2 Cannot initialize the data source object
      of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
    

    Solution

    File was open. Close it.

    Credit

    • https://stackoverflow.com/a/29369868/1175496

    Error

    Access denied...Cannot get the column information...

    Error Numbers

    7399, 7350

    Error Detail

    Msg 7399, Level 16, State 1, Line 2 The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. 
      Access denied.
    Msg 7350, Level 16, State 2, Line 2 Cannot get the column information 
      from OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
    

    Solution

    Give access

    Credit

    • https://stackoverflow.com/a/27509955/1175496

    Error

    No value given for one or more required parameters....Cannot execute the query ...

    Error Numbers

    ???, 7320

    Error Detail

    OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "No value given for one or more required parameters.".
    Msg 7320, Level 16, State 2, Line 2
    Cannot execute the query "select [Col A], [Col A] FROM $Sheet" against OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)". 
    

    Solution

    Column names might be wrong. Do [Col A] and [Col B] actually exist in your spreadsheet?


    Error

    "Unspecified error"...Cannot initialize data source object...

    Error Numbers

    ???, 7303

    Error Detail

    OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" returned message "Unspecified error".
    Msg 7303, Level 16, State 1, Line 2 Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
    

    Solution

    Run SSMS as admin. See this question.


    Other References

    Other answers which suggest modifying properties. Not sure how modifying these two properties (checking them or unchecking them) would help.

    • https://stackoverflow.com/a/31605038/1175496
    • http://www.aspsnippets.com/Articles/The-OLE-DB-provider-Microsoft.Ace.OLEDB.12.0-for-linked-server-null.aspx
    • https://social.technet.microsoft.com/Forums/lync/en-US/bb2dc720-f8f9-4b93-b5d1-cfb4f8a8b1cb/the-ole-db-provider-microsoftaceoledb120-for-linked-server-null-reported-an-error-access?forum=sqldataaccess#3fcc14f4-420e-4544-be74-eea1e0e78462
    0 讨论(0)
  • 2020-12-02 17:48

    For me it was the permission on the file's folder. I had to add all permissions for user "Everyone". Folder/properties/security -> add user everyone and set all permissions.

    0 讨论(0)
  • 2020-12-02 17:51

    Instead of changing the user, I've found this advise:

    https://social.technet.microsoft.com/Forums/lync/en-US/bb2dc720-f8f9-4b93-b5d1-cfb4f8a8b1cb/the-ole-db-provider-microsoftaceoledb120-for-linked-server-null-reported-an-error-access?forum=sqldataaccess

    This might help someone else out - after trying every solution to trying and fix this error on SQL 64..

    Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".

    ..I found an article here...

    http://sqlserverpedia.com/blog/sql-server-bloggers/too-many-bits/

    ..which suggested I give Everyone full permission on this folder..

    C:\Users\SQL Service account name\AppData\Local\Temp

    And hey presto! My query suddenly burst into life. I punched the air in delight.

    Edwaldo

    0 讨论(0)
  • 2020-12-02 17:51

    With SQL 2014, I changed the SQL Server Service (MSSQL) to run as LocalSystem. This solved the problem for me.

    It used to work as NT_SERVICE\MSSQL$MSSQL fine under 2008, from what I remember.

    0 讨论(0)
  • 2020-12-02 17:54

    There are two crucial nonobvious settings that I've discovered when tuning linked servers on Excel under SQL Server 2014. With those settings, ' FROM OPENDATASOURCE(''Microsoft.ACE.OLEDB.16.0'', ...)' as well as '... FROM [' + @srv_name + ']...data AS xl ...' function properly.

    Linked server creation

    This is just for context.

    DECLARE @DB_NAME NVARCHAR(30) = DB_NAME();
    DECLARE @srv_name nvarchar(64) = N'<srv_base_name>@' + @DB_NAME; --to distinguish linked server usage by different databases
    
    EXEC sp_addlinkedserver
        @server=@srv_name,
        @srvproduct=N'OLE DB Provider for ACE 16.0',
        @provider= N'Microsoft.ACE.OLEDB.16.0',
        @datasrc= '<local_file_path>\<excel_workbook_name>.xlsx',
        @provstr= N'Excel 12.0;HDR=YES;IMEX=0'
    ;
    
    1. @datasrc: Encoding is crucial here: varchar instead of nvarchar.
    2. @provstr: Verion, settings and sytax are important!
    3. @provider: Specify the provider installed in your SQL Server environment. Available providers are enumerated under Server Objects::Linked Servers::Providers in SSMS's Object Explorer.

    Providing access to the linked server under specific SQL Server logins

    This is the first crucial setting. Even for SA like for any other SQL Server login:

    EXEC sp_addlinkedsrvlogin @rmtsrvname = @srv_name, @locallogin = N'sa', @useself = N'False', @rmtuser = N'admin', @rmtpassword = N''
    ;
    
    1. @rmtuser: It should be admin. Actually, there is no any admin in Windows logins on the system at the same time.
    2. @rmtpassword: It should be an empty string.

    Providing access to the linked server via ad hoc queries

    This is the second crucial setting. Setting Ad Hoc Distributed Queries to 1 is not enough. One should set to 0 the DisallowAdhocAccess registry key explicitly for the driver specified to @provider:

    [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL12.DEF_INST\Providers\Microsoft.ACE.OLEDB.16.0]
    "DisallowAdhocAccess"=dword:00000000
    
    0 讨论(0)
  • 2020-12-02 17:55

    Here is specifically what worked for me only when the Excel file being queried was not open and when running the SQL Server Service as me [as a user that has access to the file system]. I see pieces of my answer already given elsewhere, so I apologize for any redundancy, but for the sake of a more succinct answer:

    USE [master]
    GO
    
    EXEC sp_configure 'Show Advanced Options', 1
    RECONFIGURE
    GO
    
    EXEC sp_configure 'Ad Hoc Distributed Queries', 1
    RECONFIGURE
    GO
    
    EXEC sp_MSSet_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
    GO
    
    EXEC sp_MSSet_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
    GO
    
    
    SELECT * 
    FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
                    'Excel 12.0;Database=C:\MyExcelFile.xlsx',
                    'SELECT * FROM [MyExcelSheetName$]')
    
    0 讨论(0)
提交回复
热议问题