How to integrate Microsoft Enterprise Library 5.0 with MySQL Databases

Source: Internet
Author: User
Tags connectionstrings

Today, I found on the Internet how to integrate Microsoft Enterprise Library 5.0 into the MySQL database, and found only the extension module of entlib 4.1,

Http://entlibcontrib.codeplex.com/, according to the above instructions after the preparation is still not successful.

So I had to manually modify it to support entlib 5.0.

Modified project: MySqlDAAB.rar

MySql. Data. dll: MySql. Data. dll

1. Modify the MySqlDatabaseAssembler. cs file.

Public class MySqlDatabaseData: DatabaseData
{
# Region Public Methods
Public MySqlDatabaseData (ConnectionStringSettings connectionStringSettings, IConfigurationSource configurationSource)
: Base (connectionStringSettings, configurationSource)
{
}
# Endregion

Public override System. Collections. Generic. IEnumerable <Microsoft. Practices. EnterpriseLibrary. Common. Configuration. ContainerModel. TypeRegistration> GetRegistrations ()
{
Yield return new TypeRegistration <Database> (
() => New MySqlDatabase (
ConnectionString,
Container. Resolved <IDataInstrumentationProvider> (Name ))){
Name = Name,
Lifetime = TypeRegistrationLifetime. Transient
};
}
}

2. Modify the constructor in the MySqlDatabase. cs file and add the configuration attribute to the MySqlDatabase class.

[ConfigurationElementType (typeof (MySqlDatabaseData)]
Public class MySqlDatabase: Database
{
Public MySQLDatabase (string connectionstring)
: Base (connectionstring, mysqlclientfactory. instance)
{
}
Public MySQLDatabase (string connectionstring, idatainstrumentationprovider instrumentationprovider)
: Base (connectionstring, mysqlclientfactory. instance, instrumentationprovider)
{
}

3. Compile the MySqlDAAB Project

4. Reference The MySqlDAAB project in the project

5. The configuration file is as follows:

<Configsections>
<Section name = "dataconfiguration"
Type = "Microsoft. Practices. enterpriselibrary. Data. configuration. databasesettings,
Microsoft. Practices. enterpriselibrary. Data "/>
</Configsections>
<Dataconfiguration>
<Providermappings>
<Add name = "mysql. Data. mysqlclient"
Databasetype = "entlibcontrib. Data. MySQL. MySQLDatabase, mysqldaab"/>
</Providermappings>
</Dataconfiguration>
<System. Data>
<Dbproviderfactories>
<Add
Name = "My SQL data provider factory"
Invariant = "mysql. Data. mysqlclient"
Description = ""
Type = "mysql. Data. mysqlclient. mysqlclientfactory"/>
</Dbproviderfactories>
</System. Data>
<Connectionstrings>
<Add name = "testdb_mysql"

Connectionstring = "Server = 127.0.0.1; database = test; user id = root; Password = ***; persist Security info = true ;"
Providername = "mysql. Data. mysqlclient"/>
</Connectionstrings>

In this way, you can use the MySQL database.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.