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.
Sanjeeb LenkaPosted Jul 23, 2013, 12:30 AM
http://forums.asp.net/post/4667932.aspx
Riyaz AkhtarPosted Jul 23, 2013, 12:22 AM
http://blog.sqlauthority.com/2010/11/03/sql-server-fix-error-ms-jet-oledb-4-0-cannot-be-used-for-distributed-queries-because-the-provider-is-used-to-run-in-apartment-mode/
Iftikar HussainPosted Jul 23, 2013, 12:01 AM
Please refer the below link
http://forums.asp.net/t/1736766.aspx/1
Regards,
Iftikar