Monday, December 23, 2013

MS SQL SERVER READ EXCEL FILE (EXCEL 2010, 2013) - OPENROWSET (x64) - (T-SQL)


There are some challenges that you might experience reading excel files running SQL server on x64 machines. Usually, everything works fine on 32-bit systems, but apparently there are some issues on 64-bit system though.
Here is the most often error appearing and definitely it doesn't tell us to much about the real cause of the problem:

Msg 7399, Level 16, State 1, Line 1

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.
 


SYSTEM REQUIREMENTS:

The following solutions could be helpful in the most cases, so follow all of these steps and requirements as well.
Requirements for 64-bit system are:
  1. Remove all x32 Office and Microsoft Access Database Engine x32 from your machine (sometimes both of these should be uninstalled to get )
  2. Install Microsoft access database engine 2010 x64: http://www.microsoft.com/en-ca/download/details.aspx?id=13255
  3. Optionally, install x64 Office if you previously uninstalled it in step 1

ENABLE AD HOC QUERIES AND OLEDB PROPERTIES

/*AD HOC QUERIES*/
sp_configure 'show advanced options', 1;

RECONFIGURE;
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE;
GO

Office 2010: 
/*OLEDB PROPERTIES*/
EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1
GO
EXEC master . dbo. sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 1
GO

Office 2013: 
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.15.0', N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.15.0', N'DynamicParameters', 1



OPENROWSET QUERIES

Office 2010: 
SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\temp\test.xlsx;HDR=NO;IMEX=1', 'SELECT * FROM [Sheet1$]')

Office 2013: 
SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.15.0', 'Excel 12.0;Database=c:\temp\test.xlsx;;HDR=NO;IMEX=1', [Sheet1$])

ADITIONAL TROUBLESHOOTING
It's not recommending, try running SQL Server Management Studio as Administrator (Right Click and Run As Administrator)


Mike C.    

8 comments:

  1. Hello,

    Thank you for your post.

    We updated Excel 2010 To Excel 2013, I received this message:
    OLE DB provider 'Microsoft.ACE.OLEDB.15.0' cannot be used FOR distributed queries because the provider IS configured TO run IN single-threaded apartment mode.

    Before, it worked with Excel 2010 (32bits) with the same recommendation like you.
    With Excel 2013, I tried also your tips but it doesn't work.

    I searched on Google but I don't find anything, I find more information about Excel 2010 instead of 2013.

    Do you have a new tip ?

    ReplyDelete
  2. Hi there,

    Strange.
    What's the account that SQL Server is running on (network service, domain account, local service, ...)? What SQL Server version you are using there?
    Are you trying to read the file from network shared folder or maybe from local hard drive?

    I will appreciate if you can provide me with some details. Also, I will try to replicate this issue somehow on my test environment.

    ReplyDelete
  3. Hi,

    Here is my test environment:
    - My account is sysadmin in SQL Server.
    - I am connected in Terminal Server as Administrator
    - The SQL server installed on the same server.
    - The excel file is on the local hard drive

    Example:
    SELECT * FROM OPENROWSET('Microsoft.ACE.OLEDB.15.0', 'Excel 12.0;Database=C:\test1.xlsx;HDR=YES;IMEX=1', 'SELECT * FROM [Feuil1$]')

    Thx
    Lau

    ReplyDelete
  4. Extra information:
    My environment is ;
    Server : Windows server 2008 R2 (64 bits)
    SQL Server Standard Edition 2008 R2 (64 bits)
    Microsoft Office Professional Plus 2013 (32 bits)

    Lau

    ReplyDelete
  5. The 32-bit OLE DB provider "Microsoft.ACE.OLEDB.12.0" cannot be loaded in-process on a 64-bit SQL Server.

    you know, how to fix it?

    ReplyDelete
  6. Reggy,

    32-bit will not work on your machine by default as it's 64-bit, but there is a way to make it working in both VS and SQL job.

    Visual Studio SSIS solution: Right click on your solution (top of hierarchy in solution explorer) -> Properties -> Configuration Properties -> Debugging -> Change "Run64BitRuntime" property to "false".

    SQL Job: Right click on SQL job -> Properties -> Steps -> select step which is importing excel file and "Edit" - > Configuration tab -> Advanced -> make sure that "32-bit Runtime" option is selected at the bottom.

    Hope this helps.


    Mladen

    ReplyDelete
  7. You know what... it works. Just in my case, I changed the folder location; I think it could be a problem because of the path length.

    ReplyDelete
  8. This comment has been removed by a blog administrator.

    ReplyDelete