简体   繁体   中英

Reading excel sheet data from SQL query in stored procedure in Azure SQL

I am trying to read data from excel file from SQL query and insert it in temp table but not able to read the data from Excel file. Getting Below Errors:

  1. 'OPENDATASOURCE' rowset provider not supported in this version of SQL Server.
  2. 'OPENROWSET' rowset provider not supported in this version of SQL Server.
  3. Linked servers are not supported in this version of SQL Server.

Below Solutions Tried:

SELECT * FROM OPENROWSET(
    'Microsoft.ACE.OLEDB.12.0',
    'Excel 8.0;HDR=NO;Database=T:\temp\Test.xlsx',
    'select * from [sheet1$]')

SELECT * FROM OPENDATASOURCE('Microsoft.ACE.OLEDB.12.0', 'Data Source=C:\Users\Downloads\Excel Logic File.xlsx;Extended Properties=EXCEL 12.0')..[Sheet1$];

Also Tried Executing below before running the query:

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO

Getting the error( Linked servers are not supported in this version of SQL Server.) EXEC ('select * from table') at linkedserver

  • I have tried to Import the data to Azure SQL from On-Premises Excel, got the same error. 在此处输入图像描述

'OPENROWSET' rowset provider not supported in this version of SQL Server.

As mentioned in MSDoc OPENDATASOURCE and OPENROWSET are supported in Azure SQL Database but the data file must be in Azure Blob Storage to use the BULK option.

Create external data source and upload sample excel file in Azure Blob Storage. Add the required file formats(Please check the following sample)

CREATE  EXTERNAL  DATA  SOURCE mydata
WITH (
TYPE  = BLOB_STORAGE,
LOCATION =  'https://blb1209.blob.core.windows.net'
);
 
SELECT  *  FROM  OPENROWSET(
BULK  'data/sample3.csv',
DATA_SOURCE =  'mydata',
SINGLE_CLOB) AS DataFile;

在此处输入图像描述

From On-Premise

Able to Import the Data from Excel using Tasks => Import Data

Check the below workaround.

We can Import Excel Data to Azur SQL using many ways.

Right click on your DB => Tasks => Import Data Select the DataSource as Excel = > Browse your Excel file

在此处输入图像描述

Select Destination as Microsoft OLEDB Provider for SQL Server => Enter credentials for SQL Server Authentication

在此处输入图像描述

Output in On-prem: 在此处输入图像描述

Output in Azure SQL 在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM