Overloaded methods for DatabaseFactory.CreateDatabase

Topics: Data Access Application Block
Apr 29, 2010 at 6:08 PM

Currently, in the base Enterprise Library, the DatabaseFactory.CreateDatabase method only exposes the ability to create a database based on a connection string defined in a configuration file.  However, I would like the ability to populate it with the ProviderName in a manner similar to what is natively available in ADO.Net 2.0 using DbProviderFactories.GetFactory("System.Data.SqlClient") in order to obtain a handle to appropriate database provider.

This is the code that I currently have to write in order to accomplish this functionality:

public static Database CreateDatabaseFactory(string strProviderName, string strConnString)
        {
            Database db = null;

                      
            switch (strProviderName)
            {
                case "System.Data.SqlClient":
                    SqlDatabase sqlDb = new SqlDatabase(strConnString);
                    db = sqlDb;
                    break;
                case "System.Data.OracleClient":
                    OracleDatabase oracleDb = new OracleDatabase(strConnString);
                    db = oracleDb;
                    break;
                case "Oracle.DataAccess.Client":
                    EntLibContrib.Data.OdpNet.OracleDatabase odpNetDb = new EntLibContrib.Data.OdpNet.OracleDatabase(strConnString);
                    db = odpNetDb;
                    break;
                default:
                    SqlDatabase defaultDb = new SqlDatabase(strConnString);
                    db = defaultDb;
                    break;
            }//switch

            return db;
        }//method: CreateDatabaseFactory()

Is there any way to expose this functionality directly through the base Enterprise Library DatabaseFactory.CreateDatabase method rather than having to provide this implementation myself?

Thanks.

Apr 29, 2010 at 9:36 PM

The assumption always was if you know the provider name, you know which physical database you want, so you can just new up the particular concrete database type yourself. There's no plan to do this in the data block at this time.