The Provider Factory in ADO.NET 2.0 - Data Providers on This Machine
(Page 2 of 4 )
In order to find a specific DbProviderFactory on this machine let us place a button and a textbox and use the GetFactory(string) method as shown from its definition in the object browser (copied from the ObjectBrowser in VS 2005).
GetFactory(string) As SYStem.Data.Common.DbProviderFactory
Public Shared Function GetFactory(ByVal providerInvariantName As String)
As & _
System.Data.Common.DbProviderFactory
Member of: System.Data.Common.DbProviderFactories
Summary:
Returns an instance of a System.Data.Common.DbProviderFactory.
Parameters:
providerInvariantName: Invariant name of a provider.
Return Values:
An instance of a System.Data.Common.DbProviderFactory for a specified
provider name.
All providers have what is called a providerInvariantName. This GetFactory() method needs to be called by providing a providerInvariantName as a string. To the click event of the button add the following code. It is assumed that you have the imports statements (System.Data and System.Data.Common) in place.
Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim strg As System.Data.Common.DbProviderFactory
dstrg = Data.Common.DbProviderFactories.GetFactory
("System.Data.SqlClient")
TextBox1.Text = dstrg.ToString
End Sub
The above code returns the following as the reference to the DbProviderFactory.
Next: More Data Providers on This Machine >>
More .NET Articles
More By Jayaram Krishnaswamy