A blog about designing and developing Business Intelligence solutions using Microsoft SQL Server
Header

Getting a List of Installed OLE DB Providers in .NET

October 12th, 2011 | Posted by David Stewart in .NET

Recently I was working on a little side project, where I needed to allow users to connect to a variety of data sources using several connection types – SQL Server, OLE DB and ODBC. Unless I wanted users to manually type in the OLE DB provider (errr… I had no intention of even doing this myself…) then I needed to populate a list of installed OLE DB providers on the current machine.

Having had very little experience in .NET programming I searched around a bit and found a few less the elegant solutions, but was surprised just how simple it was to do in the end. In fact there’s a class to do it… OleDbEnumerator

There’s a couple of methods of interest in the class – GetElements() which returns a data table containing information about the installed OLE DB providers, and GetRootEnumerator() which returns a data reader with information about the installed OLE DB providers.

In a windows forms application, populating a data grid view is as simple as one line:

1
2
3
' Set the data source of the data grid view to the
' data table returned by GetElements()
DataGridView1.DataSource = New OleDbEnumerator().GetElements()

The resulting data grid view is shown below.

OLE DB Provider List

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

One Response

  • Crazy Adam says:

    I LOVE YOU!

    I was just putting together some B.S. registry search garbage until I came upon your post.

    For those doing this in PowerShell, here is the two liner that implements David’s vision:

    [System.Data.OleDb.OleDbEnumerator]$oledb = new-object ‘System.Data.OleDb.OleDbEnumerator’
    $oledb.GetElements() | select sources_name, sources_description

    Thanks Bro,
    ~CA



Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>