Click here to Skip to main content
13,350,861 members (53,836 online)
Click here to Skip to main content
Add your own
alternative version


31 bookmarked
Posted 9 Jun 2005

MySQL connector for Microsoft Enterprise Library (January 2005 version)

, 9 Jun 2005
Rate this:
Please Sign up or sign in to vote.
Adds support for MySQL databases in the Data Access Application Block.

Sample Image - pponline.gif

Note: This article is now outdated due to changes in the Enterprise Library.


This code adds support for MySQL database access to the Data Access Application Block of the Microsoft Enterprise Library.


The Microsoft Enterprise Library defines and implements "Application Blocks". Application blocks are reusable software components designed to assist developers with common enterprise (or not) development challenges.

This code uses the native MySQL .NET Connector assembly.

Rebuilding the Data Application Block

In order to get MySQL support, you need to rebuild the Data Application Block. Under the default install path (C:\Program Files\Microsoft Enterprise Library\src\Data), create a MySql subfolder and extract the source files (MySqlDatabase.cs and MySqlCommandWrapper.cs). Open the Data.sln project and add these two files to the Data project. Add also a reference to the MySql.Data.dll assembly. Rebuild.

Adding a new connector to the Data Access block

A new connector is a class which derives from the abstract Database class. It must at least override all abstract functions. A new command wrapper class MySqlCommandWrapper which implements the DBCommandWrapper class helps limiting the functionalities (not supported stored procedure access, ...). See the files in C:\Program Files\Microsoft Enterprise Library\src\Data\Sql\ folder to go further.

Using the code

Here is a simple and standard database access using the Data Application Block which selects columns "name" and "value" from the table "test":

// Create the Database object, using the default database service. The
// default database service is determined through configuration.
Database db = DatabaseFactory.CreateDatabase();

string sqlCommand = "SELECT name, value FROM test LIMIT 1,20";
DBCommandWrapper dbCommandWrapper = db.GetSqlStringCommandWrapper(sqlCommand);

StringBuilder readerData = new StringBuilder();

// The ExecuteReader call will request the connection to be closed upon
// the closing of the DataReader. The DataReader will be closed
// automatically when it is disposed.
using (IDataReader dataReader = db.ExecuteReader(dbCommandWrapper))
    // Iterate through DataReader and put results to the text box.
    // DataReaders cannot be bound to Windows Form controls (e.g. the
    // resultsDataGrid), but may be bound to Web Form controls.
    while (dataReader.Read())
        // Get the values of the 'Name' and 'Value' columns in the DataReader
        readerData.Append( " = " );


  • This connector is based on the release version of MySQL (not the beta) available at the time it is written. This version does not support stored procedures, but you can implement them easily.
  • The database independence provided by the Data Access Block is somewhat useless when using direct SQL syntax, because MySQL syntax is not T-SQL compatible. There is an open-source project (can't remember its name) which can be used to create database independent SQL queries. It would be nice to integrate it also.

Learn more

Learn more about Microsoft Patterns and Practices


  • 2005-06-09 - First release.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Benjamin Mayrargue
France France
Benjamin designs high-end software solutions in C++ and C# always using the latest technologies available, if the customer agrees !

You may also be interested in...


Comments and Discussions

QuestionDatabase independent SQL queries ? Pin
pepecandelas29-Aug-06 14:27
memberpepecandelas29-Aug-06 14:27 
GeneralSupport for Enterprise Library 2.00 Pin
RamWebReg16-Apr-06 0:05
memberRamWebReg16-Apr-06 0:05 
GeneralRe: Support for Enterprise Library 2.00 Pin
Benjamin.Mayrargue16-Apr-06 1:33
memberBenjamin.Mayrargue16-Apr-06 1:33 
QuestionRe: Support for Enterprise Library 2.00 Pin
mobil200130-May-06 11:33
membermobil200130-May-06 11:33 
AnswerRe: Support for Enterprise Library 2.00 Pin
Mark Pryce-Maher18-Sep-06 2:24
memberMark Pryce-Maher18-Sep-06 2:24 
QuestionThis Article is Out of Date? Pin
f2092-Feb-06 15:04
memberf2092-Feb-06 15:04 
AnswerRe: This Article is Out of Date? Pin
Benjamin.Mayrargue16-Apr-06 1:32
memberBenjamin.Mayrargue16-Apr-06 1:32 
GeneralMySql 5.0 version of the wrapper Pin
melntess5-Jan-06 7:03
membermelntess5-Jan-06 7:03 
GeneralRe: MySql 5.0 version of the wrapper Pin
Benjamin.Mayrargue27-Jan-06 2:58
memberBenjamin.Mayrargue27-Jan-06 2:58 
GeneralRe: MySql 5.0 version of the wrapper Pin
galediaz23-Aug-06 9:20
membergalediaz23-Aug-06 9:20 
GeneralRe: MySql 5.0 version of the wrapper Pin
f2092-Feb-06 15:10
memberf2092-Feb-06 15:10 
Where can I get a copy of this updated version of the DAAB that works with stored procedures.


Frank Walsh
QuestionRe: MySql 5.0 version of the wrapper Pin
templar197117-Jan-07 20:50
membertemplar197117-Jan-07 20:50 
GeneralRe: MySql 5.0 version of the wrapper Pin
zhongxunyang3-Sep-07 18:08
memberzhongxunyang3-Sep-07 18:08 
GeneralDbCommandWrapper Now is Not use In Enterprise Library Pin
sehatrosny19-Nov-05 19:47
membersehatrosny19-Nov-05 19:47 
GeneralRe: DbCommandWrapper Now is Not use In Enterprise Library Pin
Benjamin.Mayrargue27-Jan-06 3:01
memberBenjamin.Mayrargue27-Jan-06 3:01 
GeneralHangs across Network Pin
brandons1-Nov-05 9:05
memberbrandons1-Nov-05 9:05 
GeneralEnterpriseLibrary &amp; MySQL Pin
Thomas Fox24-Jun-05 4:45
sussThomas Fox24-Jun-05 4:45 
Generalwhere is MySqlPermissionAttribute Pin
coffeechina12-Jun-05 6:01
membercoffeechina12-Jun-05 6:01 
GeneralRe: where is MySqlPermissionAttribute Pin
Benjamin.Mayrargue27-Jan-06 2:59
memberBenjamin.Mayrargue27-Jan-06 2:59 
Generalwhy not reference in config console Pin
coffeechina12-Jun-05 5:53
membercoffeechina12-Jun-05 5:53 
GeneralRe: why not reference in config console Pin
Benjamin.Mayrargue27-Jan-06 2:59
memberBenjamin.Mayrargue27-Jan-06 2:59 
Generalwhy not reference mysql in config console Pin
coffeechina12-Jun-05 5:51
membercoffeechina12-Jun-05 5:51 
GeneralRe: why not reference mysql in config console Pin
Benjamin.Mayrargue27-Jan-06 2:59
memberBenjamin.Mayrargue27-Jan-06 2:59 
GeneralMySql and large blobs Pin
Keith Farmer9-Jun-05 8:14
memberKeith Farmer9-Jun-05 8:14 
GeneralRe: MySql and large blobs Pin
Benjamin.Mayrargue9-Jun-05 21:40
memberBenjamin.Mayrargue9-Jun-05 21:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180111.1 | Last Updated 9 Jun 2005
Article Copyright 2005 by Benjamin Mayrargue
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid