日期:2014-05-17  浏览次数:20580 次

sql server 2008读取excel文件
首先说下环境,我是64位的系统,但是office是32位的;读取语句如下
SQL code
select * from opendatasource('Microsoft.Ace.OLEDB.12.0','Data Source=D:/Book1.xls;Extended properties=Excel 12.0;hdr=yes;IMEX=1')...[sheet1$]

在这之前有设置过
SQL code

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 
sp_configure 'show advanced options',1
go
reconfigure
sp_configure 'Ad Hoc Distributed Queries',1
reconfigure
go
sp_configure 'ole automation procedures',1
reconfigure
sp_configure 'xp_cmdshell',1
reconfigure

此时出现如下问题:Msg 7308, Level 16, State 1, Line 1
OLE DB provider 'Microsoft.Ace.OLEDB.12.0' cannot be used for distributed queries because the provider is configured to run in single-threaded apartment mode.
请教各位大虾该如何解决?

------解决方案--------------------
office你是不是还是03?Microsoft.Ace.OLEDB.12.0 这个错好像是2007了。
------解决方案--------------------
把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 
中一条注释掉,执行看看
------解决方案--------------------
参考http://blog.csdn.net/orchidcat/article/details/7480680
------解决方案--------------------
http://topic.csdn.net/u/20101213/18/e60fb52c-a7f2-41cb-b199-7dac974b2dbe.html
有个类似的。报错消息也是7308
------解决方案--------------------
用户权限不足? lz用的是本地账户?