OpenDataSource Usage
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了OpenDataSource Usage相关的知识,希望对你有一定的参考价值。
OpenDataSource 使用ad hoc 链接信息链接到Remote Data Source,而不是使用Linked Server,而OpenDataSource Row Set函数的作用是在使用 four-part object name 定位一个object时,提供ServerName\InstanceName。SQL Server 任何一个Object完全指定的命名结构依次是:Server Name,Instance Name,Database name,Schema Name,Object name。
Provides ad hoc connection information as part of a four-part object name without using a linked server name.
Openquery 函数是不确定性的函数,就是说,对于相同的输入值,不保证每次返回的值都是相同的。
All rowset functions are nondeterministic. This means these functions do not always return the same results every time they are called, even with the same set of input values.
Syntax
OPENDATASOURCE ( provider_name, init_string )
Arguments
Remarks
OPENDATASOURCE can be used to access remote data from OLE DB data sources only when the DisallowAdhocAccess registry option is explicitly set to 0 for the specified provider, and the Ad Hoc Distributed Queries advanced configuration option is enabled. When these options are not set, the default behavior does not allow for ad hoc access.
The OPENDATASOURCE function can be used in the same Transact-SQL syntax locations as a linked-server name. Therefore, OPENDATASOURCE can be used as the first part of a four-part name that refers to a table or view name in a SELECT, INSERT, UPDATE, or DELETE statement, or to a remote stored procedure in an EXECUTE statement. When executing remote stored procedures, OPENDATASOURCE should refer to another instance of SQL Server. OPENDATASOURCE does not accept variables for its arguments.
Like the OPENROWSET function, OPENDATASOURCE should only reference OLE DB data sources that are accessed infrequently. Define a linked server for any data sources accessed more than several times. Neither OPENDATASOURCE nor OPENROWSET provide all the functionality of linked-server definitions, such as security management and the ability to query catalog information. All connection information, including passwords, must be provided every time that OPENDATASOURCE is called.
Example
SELECT *
FROM OPENDATASOURCE(‘SQLNCLI‘,
‘Data Source=London\Payroll;Integrated Security=SSPI‘)
.AdventureWorks2012.HumanResources.Employee
SELECT * FROM OPENDATASOURCE(‘Microsoft.Jet.OLEDB.4.0‘,
‘Data Source=C:\DataFolder\Documents\TestExcel.xls;Extended Properties=EXCEL 5.0‘)...[Sheet1$] ;
引用文档:MSDN OPENDATASOURCE (Transact-SQL)
以上是关于OpenDataSource Usage的主要内容,如果未能解决你的问题,请参考以下文章
sql MS SQL OpenRowSet和OpenDataSource示例
SQL - OPENDATASOURCE - 名称中带有连字符的 Excel 工作表
sql server OpenDataSource查询excel数据
OPENDATASOURCE读取远程数据库数据中文乱码问题-sqlserver R2
SQL Server 阻止了对组件 'Ad Hoc Distributed Queries' 的 STATEMENT 'OpenRowset/OpenDatasource