3
Answers

Error while uploading excel file in sql server using asp.net

baskaran chellasamy

baskaran chellasamy

11y
1.4k
1
Hi friends

  The following is my query for uploading excel file to sql table

alter procedure [dbo].[sp_excelforgeneralholidays](@filname nvarchar(max),@getdate datetime,@adminid int)
 as  
 begin
 exec sp_configure 'Ad Hoc Distributed Queries',1
 
RECONFIGURE;
 declare @datavar nvarchar(max)
 declare @sql varchar(1000)
 --set @getdate=coalesce(@getdate,Getdate())
 set @datavar  = 'Excel 8.0;Database=' + @filname
 
 set nocount on
   --create table #temptable (Date date ,Day varchar(30),Reason varchar(100))
  set @sql ='insert into Generalholyday_details(Date,Day,Reason) SELECT * FROM OPENROWSET(''Microsoft.jet.OLEDB.4.0'','''+@datavar+';HDR=YES'',''SELECT Date,Day,Reason FROM [Sheet1$]'')'
  
  
   exec (@sql)
   update Generalholyday_details set createddatetime= @getdate where createddatetime is null
   update Generalholyday_details set adminid=@adminid where adminid is null
   end



but  following error is occured

OLE DB provider 'Microsoft.jet.OLEDB.4.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.
Configuration option 'Ad Hoc Distributed Queries' changed from 1 to 1. Run the RECONFIGURE statement to install.

Answers (3)