大网数据广告活动
域与目录服务

Searching with OLE DB

· 52CE 我爱测

For both Automation clients using ActiveX Data Objects (ADO) and all non-Automation clients, ADSI supplies an OLE DB provider that supports a subset of OLE DB query interfaces.

For both Automation clients using ActiveX Data Objects (ADO) and all non-Automation clients, ADSI supplies an OLE DB provider that supports a subset of OLE DB query interfaces. Client code that already uses OLE DB interfaces for queries can use the same interfaces to query directory services.

Under the OLE DB implementation, a directory service is exposed as a Data Source object. Data Source objects are factories for session objects and support IDBInitialize to connect to the directory, IDBCreateSession to create the session object, IDBProperties to supply authentication data to the underlying namespace and supply the query command and IPersist to save the data necessary to create the data source object to the underlying directory service.

To perform an Active Directory query using OLE DB

  1. Retrieve the IDBInitialize interface from the OLE DB provider. In the case of Active Directory, use the class identifier CLSID_ADsDSOObject.
  2. Build a DBPROP array of connection data specifying user name and password.
  3. Query the IDBInitialize interface retrieved in Step 1 for the IDBProperties interface.
  4. Call the IDBProperties::SetProperties method passing in the DBPROP array created in Step 2.
  5. Call the IDBInitialize::Initialize method to establish the connection to the OLE DB provider; that is the Active Directory provider, in this case.
  6. Query the IDBInitialize interface for the IDBCreateSession interface.
  7. Call the IDBCreateSession::CreateSession method requesting a new interface of type IDBCreateCommand.
  8. Call the IDBCreateCommand::CreateCommand method to create an ICommandText interface.
  9. Call the ICommandText::SetCommandText method. Pass in the preferred dialect and the actual query command text in that dialect. Either DBGUID_LDAPDialect or DBGUID_DBSQL may be used as the dialect.
  10. Call ICommand::Execute; an IRowset interface is returned which is the interface to the result set.
  11. Query the IRowset interface for the IColumnsInfo interface.
  12. Call the IColumnsInfo::GetColumnInfo method to retrieve column data about the result set.
  13. Populate an array of DBBINDING structures, describing to the OLE DB provider how to expose the data types on a per-column basis to the application code. This step enables you to specify which TYPE is contained in a particular column. Also the offsets of the columns, relative to the returned row, are set here on a column-by-column basis.
  14. Query the IRowset interface for the IAccessor interface.
  15. Call the IAccessor::CreateAccessor method, which returns an array of accessor handles. This array is then used to access the rows of the result set.
  16. Call IRowset::GetNextRows passing in the row handles, and number of rows to get.
  17. Call IRowset::GetData passing in a row handle, from the set returned in Step 16. A raw pointer to the row is returned.

For more information about the search filter syntax, see Search Filter Syntax.

To read the unprocessed row data returned, use the DBBINDING structure, created in Step 13, compute the column offsets in the unprocessed data pointer returned in Step 17. Read the status portion of the column for a retrieval result on that column.

For more information and a code example that shows how to search Active Directory using the ADSI OLE DB provider, see Example Code for Using OLE DB to Search Active Directory.

Source: Microsoft Learn / Windows Win32 documentation by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / Windows Win32 documentation
适用范围
Windows Win32 API · Source date 05/31/2018
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。