Click here to Skip to main content
15,895,462 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi

I have an issue that how to upload excel 2016 xlsx file into mssql 2017 server
Previously I use excel 2010 and Mssql 2012. The code is working fine (Given Below)

Now our client upgrade Office 2016 and MSSql server 2017 and VS 2017

Pls Advice Me

Thank you

Maideen

What I have tried:

This is Web.Config

SQL
<add name="Excel07ConString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0};Extended Properties='Excel 8.0;HDR={1}'"/>


Stored Procedure

ALTER PROCEDURE [dbo].[ZR_usp_ImportFromExcel07]
   @SheetName varchar(20),
   @FilePath varchar(100),
   @HDR varchar(3),
   @TableName varchar(50)
AS
BEGIN
    
	DECLARE @SQL nvarchar(1000)
	SET @SQL = 'TRUNCATE TABLE ' + @TABLENAME
	EXEC(@SQL)

    IF OBJECT_ID (@TableName,'U') IS NOT NULL
      SET @SQL = 'INSERT INTO ' + @TableName + ' SELECT * FROM OPENDATASOURCE'
    ELSE
      SET @SQL = 'SELECT * INTO ' + @TableName + ' FROM OPENDATASOURCE'
 
    SET @SQL = @SQL + '(''Microsoft.ACE.OLEDB.16.0'',''Data Source='
    SET @SQL = @SQL + @FilePath + ';Extended Properties=''''Excel 16.0;HDR='
    SET @SQL = @SQL + @HDR + ''''''')...['
    SET @SQL = @SQL + @SheetName + ']'
    EXEC sp_executesql @SQL


Also

EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'AllowInProcess' , 1

EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0' , N'DynamicParameters' , 1
Posted
Updated 30-Apr-19 19:54pm
Comments
ZurdoDev 1-May-19 10:48am    
Why doesn't it work anymore?

1 solution

This is a total disaster. Anything that uses sp_executesql is going to be bad. You're truncating dynamic tables?

Just read your excel file as binary data and write it as a blob.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900