OPENDATASOURCE
OPENDATASOURCE is a function in SQL Server that provides ad hoc connection information as part of a four-part object name without using a linked server name. It's typically used for accessing remote data from an OLE DB data source.
OPENDATASOURCE( provider_name , init_string )
- provider_name: This is the name of the OLE DB provider that is used to access the data source.
- init_string: This parameter refers to the connection string that is passed to the specified OLE DB provider. This string contains the properties required to establish the connection, or database session, with the data source.
Example
Output
Explanation
In the example, OPENDATASOURCE
is used to execute a query on a remote server specified by ‘ServerName’. SQLNCLI
indicates the provider name. It then accesses the Categories
table in the Northwind
database on the remote server. The output is a list of categories in the Northwind
database’s Categories
table.