11.15. Enumerating OLE DB Providers
Problem
You need a list of the OLE DB providers installed on the machine running your code.
Solution
Use the OleDbEnumerator.GetElements()
method, the OleDbEnumerator.GetEnumerator()
method, a SQL Server extended stored procedure, or search the registry. The solution demonstrates these four approaches.
The first approach uses the GetElements()
method of the OleDbEnumerator
class to retrieve a list of visible OLE DB providers and output them to the console.
The second approach uses the static GetEnumerator()
method of the OleDbEnumerator
class to retrieve a list of OLE DB providers and output them to the console.
The third approach executes the extended stored procedure xp_enum_oledb_providers
. The result set containing the installed OLE DB providers is output to the console.
In the fourth approach, the sample code uses the Microsoft.Win32.Registry
class to examine the registry, identify OLE DB provider subkeys, and retrieve and display the OLE DB provider names from these subkeys.
The C# code in Program.cs in the project EnumerateOleDbProviders
is shown in Example 11-18.
Example 11-18. File: Program.cs for EnumerateOleDbProviders solutions
using System; using System.Data; using System.Data.SqlClient; using System.Data.OleDb; using Microsoft.Win32; namespace EnumerateOleDbProviders { class Program { static void Main(string[] args) { // Enumerate OLE DB providers using GetElements( ) OleDbEnumerator e = new OleDbEnumerator( ); DataTable dt = e.GetElements( ...
Get ADO.NET 3.5 Cookbook, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.