views:

15

answers:

1

Hi,

I'm using Enterprise Library 4.1.

I have a new feature to implement and it requires the use of mysql.

I have found Enterprise Library Contrib, which adds functionalities to use MySQL with Enterprise Lib.

Works great.

To get it to work, you need to call the method 'DatabaseFactory.CreateDatabase(connectionStringName);' like you would normally do. The connection string name is stored in the configuration and linked to the database provider mapping configuration section.

As an exemple:

  <dataConfiguration defaultDatabase="MyDefaultDb">
    <providerMappings>
      <add databaseType="EntLibContrib.Data.MySql.MySqlDatabase, EntLibContrib.Data.MySql, Version=4.1.0.0, Culture=neutral, PublicKeyToken=null" 
           name="MySql.Data.MySqlClient" />
    </providerMappings>
  </dataConfiguration>
  <connectionStrings>
    <add name="MyDefaultDb" 
         connectionString="" 
         ProviderName="System.Data.SqlClient" />
    <add name="acb_leaderboards"
         providerName="MySql.Data.MySqlClient"
         connectionString="" />
  </connectionStrings>

Unfortunately, my application will connect to multiple MySQL database and the conncetion will vary from time to time. I can't have the mysql connection string be specified in the configuration.

I want to create a MySQL database object based on the providerMapping configuration.

How can I do that?

Thank you.

PS. English is not my first language, I'm trying my best.

A: 

If you know ahead of time that you're using MySql, and assuming that the MySqlDatabase class follows the same patterns as the Database classes in the core Entlib, then you can just new it up directly, you don't have to go through the factory method.

Database mySql = new MySqlDatabase(currentConnectionString);

should just work. You only need to go through the factory if you're pulling named connection strings from config.

Chris Tavares