如何找出适用于SQL Server 2008的ole提供程序?

时间:2013-03-15 14:19:44

标签: sql sql-server-2008 tsql oledb linked-server

我尝试访问MSMS中的Excel文件。在搜索互联网后,我无法正常工作。

这是我做的:
我的环境:

Windows 7(64bit) SP 1, 
Microsoft SQL Server 2008 (SP3) - 10.0.5500.0 (X64)   
Office 2010 Pro Plus with Access installed(32 bit)
  1. 尝试更改OLE的配置,如:

    exec sp_configure 'Advanced', 1
    RECONFIGURE
    
    exec sp_configure 'Ad Hoc Distributed Queries', 1
    RECONFIGURE
    
    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
    
  2. 运行查询:

    SELECT * FROM OPENROWSET('MICROSOFT.ACE.OLEDB.12.0','Text;Database=C:\Temp\;','SELECT * FROM [test.csv]')
    

    SELECT * FROM OPENROWSET('MICROSOFT.JET.OLEDB.4.0','Text;Database=C:\Temp\;','SELECT * FROM [test.csv]')
    
  3. 对于这两种情况,我收到如下错误消息:

    Msg 7308, Level 16, State 1, Line 1
    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.
    

    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.
    

    然后我检查了SQL服务器上的链接服务器,默认情况下运行系统sp:

    有10个提供程序
    EXEC master.dbo.sp_MSset_oledb_prop 
    
    SQLOLEDB
    MSOLAP
    SQLNCLI11
    ADsDSOObject
    SQLNCLI
    SQLNCLI10
    Search.CollatorDSO
    MSDASQL
    MSDAOSP
    MSIDXS
    

    如何解决此问题? 我如何知道MICROSOFT.ACE.OLEDB.12.0MICROSOFT.JET.OLEDB.4.0是否可用于SQL Server?

1 个答案:

答案 0 :(得分:2)

对于带扩展名的文件类型.xlsx使用“Excel 12.0”或“Excel 12.0 Xml”代替Excel 9.0

SELECT *
FROM OPENROWSET('Microsoft.ACE.OLEDB.12.0', 'Excel 12.0;Database=C:\Temp\Test.xlsx;', 'SELECT * FROM [Location1$]')

如果要连接到Microsoft Office Excel数据,请根据Excel文件类型添加OLEDB连接字符串的相应扩展属性:

File Type (extension)                               Extended Properties
---------------------------------------------------------------------------------
Excel 97-2003 Workbook (.xls)                       "Excel 8.0"
Excel 2007-2010 Workbook (.xlsx)                    "Excel 12.0 Xml"
Excel 2007-2010 Macro-enabled workbook (.xlsm)      "Excel 12.0 Macro"
Excel 2007-2010 Non-XML binary workbook (.xlsb)     "Excel 12.0"