How to: Enumerate OLE DB Data Sources (OLE DB)
To list the data sources visible to the SQLOLEDB enumerator, the consumer calls the ISourcesRowset::GetSourcesRowset method. This method returns a rowset of information about the currently visible data sources.
Depending on the network library used, the appropriate domain is searched for the data sources. For named pipes, it is the domain to which the client is logged on. For AppleTalk, it is the default zone. For SPX/IPX, it is the list of SQL Server installations found in the bindery. For Banyan VINES, it is the SQL Server installations found on the local network. Multiprotocol and TCP/IP sockets are not supported.
When the server is turned off or on, it can take few minutes to update the information in these domains.
A complete sample code is in the file ListDataSourcesWithEnumerator.cpp. You can download an archive containing the sample from the SQL Server Downloads page on MSDN.
This sample was developed using Microsoft Visual C++ 2005.
Security Note |
---|
When possible, use Windows Authentication. If Windows Authentication is not available, prompt users to enter their credentials at run time. Avoid storing credentials in a file. If you must persist credentials, you should encrypt them with the Win32 crypto API. |
To enumerate OLE DB data sources
Retrieve the source rowset by calling ISourceRowset::GetSourcesRowset.
Find the description of the enumerators rowset by calling GetColumnInfo::IColumnInfo.
Create the binding structures from the column information.
Create the rowset accessor by calling IAccessor::CreateAccessor.
Fetch the rows by calling IRowset::GetNextRows.
Retrieve data from the rowset's copy of the row by calling IRowset::GetData, and process it.