0

I am trying to take data from an Excel sheet and store it into SQL Server 2019 through the Openrowset statement. First I asked to enable 'ad hoc distributed queries' and 'show Advanced Options', which I did, but still alleged to execute it gets stuck and not is not providing the desired result. I'm doing this on my local computer.

Example query:

SELECT * 
FROM OPENROWSET ('Microsoft.ACE.OLEDB.12.0',
                 'Excel 12.0;Database=C:\Users\Public\Documents\Prueba.xlsx',
                 'Select * from [Hoja1$]')

AND it is a small Excel file, just a test, 10 rows, no more, I'm doing this on my local computer, I've done it before in my job computer and it works, but not here.

4
  • 1
    Do you get some kind of an error message? Please Edit your question to include the full and complete error message - as text, not screen shot(s). Commented Aug 31, 2023 at 8:32
  • These queries are executed by SQL Server, and the SQL Server service is running in the context of a particular user (see Services.msc, for example, to see which user that is). Does that service user have read/write access granted to it in the filesystem permissions for the C:\Users\Public\Documents folder? Is the Excel file closed? (Office applications hold non-shareable locks on files they have open.) Commented Aug 31, 2023 at 8:34
  • Also, Microsoft.ACE.OLEDB.12.0 (Microsoft Access Database Engine 2010) is quite old, do you have it installed? Are you not using a more current version, like Microsoft.ACE.OLEDB.16.0 (Microsoft Access Database Engine 2016)? Commented Aug 31, 2023 at 8:39
  • Note that using the ACE OLE provider as a linked server is not a supported scenario (because it's designed for GUI applications) so you won't get any help from Microsoft. It sort-of works, but don't be surprised if you have problems. Instead use a proper import tool such as SSIS. Commented Aug 31, 2023 at 13:30

1 Answer 1

0

Please try the following steps:

  1. If the *.xslx file is open in Excel, close it.
  2. Run SSMS as Administrator.
  3. Give the account used to run the SQL Server (MSSQLSERVER) service full permission on this folder where your .xlsx file is stored. On my machine account: <<Server Name>>\Network Service
  4. Is [Hoja1$] the sheet name or a defined range within the file? Sheet names are formatted as from [Sheet1$]; range names are formatted as from [$Data]. I believe you can use something like from [Sheet1$A2:M26] as well.
  5. I use the following format:
    Excel 12.0;IMEX=1;HDR=Yes;Database=F:\\temp\filename.xlsx
    

Hopefully this helps. Note as well that when the Openrowset fails the file can be locked in an open state. Additional attempts to read the file will fail, until the open lock is removed.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.