Introduction
This tip presents a simple wrapper around the System.Data.OleDb.OleDbEnumerator.GetRootEnumerator
method.
Background
I do a lot of database work with ADO.NET and I access many types of databases, some of which require OleDb, including Access and Excel. Listing the OleDb providers on a system is something I need to do from time to time, particularly when I get a new system. This small class makes accessing the enumeration just a little easier.
The Code
Your application needs only iterate the EnumerateProviders
method.
public sealed class OleDbProvider
{
public enum ProviderType
{ Binder = 0
, DataSource_MDP = 1
, DataSource_TDP = 2
, Enumerator = 3
} ;
public string Name { get ; private set ; }
public System.Guid ParseName { get ; private set ; }
public string Description { get ; private set ; }
public ProviderType Type { get ; private set ; }
public bool IsParent { get ; private set ; }
public System.Guid ClsID { get ; private set ; }
private OleDbProvider
(
System.Data.IDataRecord Record
)
{
this.Name = (string) Record [ "SOURCES_NAME" ] ;
this.ParseName = System.Guid.Parse ( (string) Record [ "SOURCES_PARSENAME" ] ) ;
this.Type = (ProviderType) Record [ "SOURCES_TYPE" ] ;
this.Description = (string) Record [ "SOURCES_DESCRIPTION" ] ;
this.IsParent = (bool) Record [ "SOURCES_ISPARENT" ] ;
this.ClsID = System.Guid.Parse ( (string) Record [ "SOURCES_CLSID" ] ) ;
return ;
}
public static System.Collections.Generic.IEnumerable<OleDbProvider>
EnumerateProviders
(
)
{
using
(
System.Data.IDataReader dr
=
System.Data.OleDb.OleDbEnumerator.GetRootEnumerator()
)
{
while ( dr.Read() )
{
yield return ( new OleDbProvider ( dr ) ) ;
}
}
yield break ;
}
}
History