Cannot create an instance of OLE DB provider Microsoft.Jet.OLEDB.4.0 for linked server null

前端 未结 4 1202
有刺的猬
有刺的猬 2020-11-29 01:44

I am trying to export from my Table data into Excel through T-SQL query. After little research I came up with this

IN         


        
4条回答
  •  天涯浪人
    2020-11-29 02:02

    Works !!! Great thanks. Just for 64-bit Win server 2012R2. Let me put the whole working script partially repeating bits from above which are not easy (as for me) to combine together:

    1) Download the Microsoft.ACE.OLEDB.12.0 for Windows, 64 bit version found here: https://www.microsoft.com/en-us/download/details.aspx?id=13255

    2) Create excel file with respective columns (name and class in this case).

    3) Run code below:

    sp_configure 'show advanced options', 1;  
    RECONFIGURE;
    GO 
    sp_configure 'Ad Hoc Distributed Queries', 1;  
    RECONFIGURE;  
    GO 
    
    /* -- Not sure commented bits are necessary but I also have run them
    EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.4.0', N'AllowInProcess', 1
    GO 
    EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.Jet.OLEDB.4.0', N'DynamicParameters', 1
    GO 
    
    -- below two lines failed with: Msg 2787, Level 16, State 1, Procedure sp_MSset_oledb_prop, Line 106 Invalid format specification: '%1!.'.
        EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1   
    EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParam', 1
    
    -- but works all two as below:
    EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1   
    EXEC sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
    -- Succeded to run after success with Excel so does not looks like necessary
    
    
    */
    
    INSERT INTO OPENROWSET('Microsoft.ACE.OLEDB.12.0', 
    'Excel 8.0;Database=C:\testing.xlsx;', 
    'SELECT Name, Class FROM [Sheet1$]') 
    SELECT [Name],[Class] FROM Qry_2
    GO
    

提交回复
热议问题