如何使用SQL Server链接服务器查询Excel数据

Linked servers allow SQL Server access to data from a remote data source. A remote data source can be another SQL Server instance or other data sources such MySQL, Access databases, Oracle, Excel workbooks, text files etc.

链接服务器允许SQL Server从远程数据源访问数据。 远程数据源可以是另一个SQL Server实例,也可以是其他数据源,例如MySQL,Access数据库,Oracle,Excel工作簿,文本文件等。

SQL Server connects to the remote data source via an OLE DB provider. There are variations of the OLE DB providers depending on data source that want to establish connection to. There are the Microsoft OLE DB Provider for Oracle, Microsoft OLE DB Provider for SQL Server, OLE DB Provider for Jet etc. providers:

SQL Server通过OLE DB提供程序连接到远程数据源。 OLE DB提供程序有所不同,具体取决于要建立连接的数据源。 有用于Oracle的 Microsoft OLE DB提供程序,用于SQL Server的Microsoft OLE DB提供 程序,用于Jet的OLE DB提供程序等提供程序:

Microsoft SQL Server supports connections to other OLE DB data sources on a persistent or an ad hoc basis. The persistent connection is known as a linked server. An ad hoc connection, that is made for the sake of a single query, is known as a distributed query.

Microsoft SQL Server支持持久地或临时地连接到其他OLE DB数据源。 持久连接称为链接服务器。 为进行单个查询而建立的临时连接称为分布式查询。

A distributed query can be run without creating a linked server first, by using the Transact-SQL OPENROWSET and OPENDATASOURCE functions.

通过使用Transact-SQL OPENROWSETOPENDATASOURCE函数,可以运行分布式查询而无需先创建链接服务器。

When executing a T-SQL statement against a linked server, the OLE DB provider (e.g. OLE DB Provider for Jet) for the linked server is loaded into the SQL Server memory address space, then SQL Server takes the T-SQL statement and calls the OLE DB interface. Then the OLE DB interface provides a connection to the remote data source (e.g. Excel file). The OLE DB provider then processes the result set and returns the results to the SQL Server client that made the initial call.

当对链接服务器执行T-SQL语句时,将链接服务器的OLE DB提供程序(例如Jet的OLE DB提供程序 )加载到SQL Server内存地址空间中,然后SQL Server接收T-SQL语句并调用OLE DB接口。 然后,OLE DB接口提供到远程数据源(例如Excel文件)的连接。 OLE DB提供程序然后处理结果集,并将结果返回给进行初始调用SQL Server客户端。

In this article we’ll show how to create a linked server to query Excel data from the Excel file (*.xlsx) using the Microsoft.ACE.OLEDB.12.0 OLE DB provider and also how can be done by using the OPENROWSET and OPENDATASOURCE functions.

在本文中,我们将展示如何使用Microsoft.ACE.OLEDB.12.0 OLE DB提供程序创建链接服务器以从Excel文件(* .xlsx)查询Excel数据,以及如何使用OPENROWSETOPENDATASOURCE进行操作功能。

使用Microsoft.ACE.OLEDB.12.0 OLE DB提供程序创建链接的服务器 (Creating a linked server with the Microsoft.ACE.OLEDB.12.0 OLE DB provider)

To import data from an Excel file (Excel 2007 (xlsx) and above) to SQL Server the Microsoft.ACE.OLEDB.12.0 OLE DB driver should be installed.

要将数据从Excel文件(Excel 2007(xlsx)及更高版本)导入SQL Server,应安装Microsoft.ACE.OLEDB.12.0 OLE DB驱动程序。

The Microsoft.ACE.OLEDB.12.0 OLE DB driver can be used on SQL Server 32-bit editions for Excel 2007 files, or later, or on SQL Server 64-bit editions for any Excel files.

Microsoft.ACE.OLEDB.12.0 OLE DB驱动程序可以在Excel 2007文件或更高版本SQL Server 32位版本上使用,或者在任何Excel文件SQL Server 64位版本上使用。

There is one more provider; Microsoft. Jet. OLEDB.4.0 which can be used on SQL Server 32-bit editions for Excel 2003 files (or earlier).

还有一个提供者; 微软。 喷射。 OLEDB.4.0可以在SQL Server 32位版本的Excel 2003文件(或更早版本)上使用。

A list of all currently available providers in SQL Server can be seen under the Providers folder:

可以在Providers文件夹下看到SQL Server中所有当前可用的提供程序的列表:

From this link you can download and install the Microsoft.ACE.OLEDB.12.0 OLE DB driver. Depending on which version of SQL Server (32-bit or 64-bit) use, there are two versions of the Microsoft.ACE.OLEDB.12.0 OLE DB driver that can be installed:

从此链接,您可以下载并安装Microsoft.ACE.OLEDB.12.0 OLE DB驱动程序。 根据使用哪个版本SQL Server(32位或64位),可以安装两个版本的Microsoft.ACE.OLEDB.12.0 OLE DB驱动程序:

  • AccessDatabaseEngine.exe is for the SQL Server 32-bit version AccessDatabaseEngine.exe适用于SQL Server 32位版本
  • AccessDatabaseEngine_X64.exe is for the SQL Server 64-bit version AccessDatabaseEngine_X64.exe适用于SQL Server 64位版本

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值