DevPinoy.org
A Filipino Developers Community
   
How To: List All Available .NET Data Providers

.NET 2.0 introduces to us the class known as DBProviderFactories which enables us to access available providers on a machine. the DBProviderFactories class has method called GetFactoryClasses() that returns a DataTable that contains any class that is registered on the GAC that implements the DBProviderFactory class.

[ C# Version ]

using System;
using System.Data;
using System.Data.Common;

namespace KeithRull.ListAllAvailableDataProviders
{
   class Program
   {
      static void Main(string[] args)
      {
         DataTable providersTable = DbProviderFactories.GetFactoryClasses();

         //loop thru each provider in the providers data table
         foreach (DataRow providerRow in providersTable.Rows)
         {
            //loop thru each column in the providers table
            foreach (DataColumn providerColumn in providersTable.Columns)
            {
               //print the information
               Console.WriteLine(providerColumn.ColumnName + ": " + providerRow[providerColumn].ToString());
            }
            //create a extra line feed for data separation
            Console.WriteLine("");
         }

      //show the information to the screen
      Console.ReadLine();
      }
   }
}

[ VB.NET Version ]

Imports System
Imports System.Data
Imports System.Data.Common

Namespace KeithRull.ListAllAvailableDataProviders
   Class Program
      Shared Sub Main(ByVal args() As String)
         Dim providersTable As DataTable = DbProviderFactories.GetFactoryClasses() 

         Dim providerRow As DataRow
         For Each providerRow In providersTable.Rows
            Dim providerColumn As DataColumn
            For Each providerColumn In providersTable.Columns
               Console.WriteLine(providerColumn.ColumnName + ": " + providerRow(providerColumn).ToString())
            Next
            Console.WriteLine("")
         Next
         Console.ReadLine()
   End Sub
End Class
End Namespace


Posted 08-27-2006 2:51 PM by keithrull
Copyright DevPinoy 2005-2008