5 The DB2 Data Provider : Provider Factories

Provider Factories
When you use the Common Programming Model, you do not need to specify the provider-specific namespace, because the Provider Factories generate instances of the specified data provider. However, if you want to use DataDirect Bulk Load, you must include the DDTek.Data.Common namespace.
The following C# code snippet obtains an instance of the DB2 data provider:
DbProviderFactory factory = DbProviderFactories.GetFactory("DDTek.DB2");
DbConnection Conn = factory.createConnection();
Conn.ConnectionString = "Host=Accounting;Port=50000;
User ID=gene;Password=b0gey;Database=test";
 
// iSeries format for the connection string
// Conn.CommandText = "Host=10.30.11.189;Port=446;
// User ID=john;Password=beAch05;Database=NCANSV5;Collection=ADOVS1";
 
// z/OS format for the connection string
// Conn.CommandText = "Host=10.30.14.109;Port=448;
// User ID=fred;Password=sailb0at;Database=S390LOC_7U";
 
try
{
    Conn.Open();
    Console.WriteLine("Connection successful! ");
}
catch (Exception ex)
{
    // Connection failed
    Console.WriteLine(ex.Message);
}
// Close the connection
Conn.Close();