The Provider Factory in ADO.NET 2.0 - More Data Providers on This Machine
(Page 3 of 4 )
System.Data.SqlClient.SqlClientFactory
To find all the different providers on this machine the GetFactoryClasses must be interrogated. This method is described as follows (copied from the ObjectBrowser in VS 2005):
GetFactoryClasses() As System.Data.DataTable
Public Shared Function GetFactoryClasses() As System.Data.DataTable
Member of: System.Data.Common.DbProviderFactories
Summary:
Returns a System.Data.DataTable that contains information about all
installed providers
that implement System.Data.Common.DbProviderFactory.
Return Values:
Returns a System.Data.DataTable containing System.Data.DataRow objects
that contain the
following data. Column ordinalColumn nameDescription 0NameHuman-readable
name for the data
provider.1DescriptionHuman-readable description of the data provider.
2InvariantNameName
that can be used programmatically to refer to the data provider.
3AssemblyQualifiedNameFully
qualified name of the factory class, which contains enough information
to instantiate the
object.
As the return value comes out in rows of data in three columns each, place a command button, a textbox and a GridView control on the form, and to the click event of the button insert the following code.
Protected Sub Button1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Button1.Click
'since we know the returned info is in a table format we start out
'with a table
Dim dtable As New DataTable
'GetDataClasses() is without any arguments
dtable = Data.Common.DbProviderFactories.GetFactoryClasses
GridView1.DataSource = dtable
GridView1.DataBind()
GridView1.Visible = True
Dim drfow As System.Data.Common.DbProviderFactory
drfow = Data.Common.DbProviderFactories.GetFactory(dtable.Rows(1))
TextBox2.Text = drfow.ToString
End Sub
When the button is clicked all the different providers are displayed in the GridView as shown in the next picture. The last two providers are not from an out-of-the box install of VS 2005. These were automatically added when Jasper (SQL Anywhere 10) was installed on this machine.

The textbox shows the variable drfow in the following paragraph corresponding to the second row.
System.Data.OleDb.OleDbFactoryIt was noted that, although the individual columns for any row should be accessible, the program throws an exception for any value other than for ColumnIndex=2 for no apparent reason.
Next: Creating Provider Independent Data Access >>
More .NET Articles
More By Jayaram Krishnaswamy