sql server sql語句導入數據到execl2007中

insert into OPENROWSET('Microsoft.ACE.OLEDB.12.0','Excel 12.0;Database=C:\c.xlsx','select 字段1,字段2 FROM [sheet1$]') 
select 字段1,字段2 from table sql

 

 

今天單位一ASP.NET網站,裏面有個功能是導出數據,發現一導出就報錯,報錯內容是:SQL Server 阻止了對組件 'Ad Hoc Distributed Queries' 的 STATEMENT'OpenRowset/OpenDatasource' 的訪問,由於此組件已做爲此服務器安全配置的一部分而被關閉。系統管理員能夠經過使用 sp_configure 啓用 'Ad Hoc Distributed Queries'。有關啓用 'Ad Hoc Distributed Queries' 的詳細信息,請參閱 SQL Server 聯機叢書中的 "外圍應用配置器"。安全

    看錯誤提示就知道是由於SQL Server的Ad Hoc Distributed Queries組件被禁用了,這裏我用的SQL Server版本是2005,只須要開啓Ad Hoc Distributed Queries就能夠了,方法以下:服務器

    1.開啓Ad Hoc Distributed Queries組件,在sql查詢編輯器中執行以下語句:
 編輯器

exec sp_configure 'show advanced options',1
reconfigure
exec sp_configure 'Ad Hoc Distributed Queries',1
reconfigure

    2.關閉Ad Hoc Distributed Queries組件,在sql查詢編輯器中執行以下語句:網站

exec sp_configure 'Ad Hoc Distributed Queries',0 reconfigure exec sp_configure 'show advanced options',0 reconfigure
相關文章
相關標籤/搜索