![]() |
Database »
Database »
General
Intermediate
Intergrating MySql with Enterprise Library for .NET Framework 2.0By Mark Pryce-MaherAn article on adding a MySql connector into Enterprise Library for .NET Framework 2.0 |
C#, Windows, .NET, Visual Studio, MySQL, DBA, Dev
|
||||||||||
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||

IntroductionI have been looking at Microsoft's Enterprise Library for .NET Framework 2.0[^] and I wondered how difficult it would be to extend the Data Access Application Block to include MySQL as one of the databases.
I found Benjamin Mayrargue's article: MySQL connector for Microsoft Enterprise Library (January 2005 version). I followed the steps he took, just to see if I could get it to work.
It didn't because it was written for a previous version of the Enterprise Library, but his article gave me all the information I needed to have a stab at doing it myself.
I also looked at the way the Oracle and SQL Server blocks were built, copied how they were built.
I have made a few assumptions;
Microsoft's Enterprise Library for .NET Framework 2.0 is a framework to base your code around, its flexible and extendable. The Data Access Block proves a database independant implementation layer for you to add into your code, although its database independant, there are only two existing providers supplied with the data access block, SQL Server and Oracle. This article shows you how to add MySql to this list, infact using the ideas from the article it should be possible to implement any .Net database connector as a Data Access Block (well thats the idea...But actually doing it might be quite tricky)
private DbProviderMapping GetDefaultMapping(string name, string dbProviderName)
if (DbProviderMapping.DefaultMySqlProviderName.Equals(dbProviderName)) return defaultMySqlMapping;
private static readonly DbProviderMapping defaultMySqlMapping = new DbProviderMapping(DbProviderMapping.DefaultMySqlProviderName, typeof(MySqlDatabase));
private IConfigurationSource configurationSource;
public class DatabaseConfigurationView { private static readonly DbProviderMapping defaultSqlMapping = new DbProviderMapping(DbProviderMapping.DefaultSqlProviderName, typeof(SqlDatabase)); private static readonly DbProviderMapping defaultOracleMapping = new DbProviderMapping(DbProviderMapping.DefaultOracleProviderName, typeof(OracleDatabase)); private static readonly DbProviderMapping defaultGenericMapping = new DbProviderMapping(DbProviderMapping.DefaultGenericProviderName, typeof(GenericDatabase)); private static readonly DbProviderMapping defaultMySqlMapping = new DbProviderMapping(DbProviderMapping.DefaultMySqlProviderName, typeof(MySqlDatabase)); private IConfigurationSource configurationSource;
/// <item>For provider name "System.Data.SqlClient", or for a provider of type <see cref="System.Data.SqlClient"/>, the
/// <see cref="Microsoft.Practices.EnterpriseLibrary.Data.MySql.MySqlDatabase"/> will be used.</item>
/// <summary>
/// Default name for the MySQL managed provider.
/// </summary>
public const string DefaultMySqlProviderName = "MySql.Data.MySqlClient";
under the public const string DefaultOracleProviderName = "System.Data.OracleClient";
using MySql.Data.MySqlClient; to DatabaseConfigurationView.cs and DbProviderMappings.cs to get it to compile.Database db = DatabaseFactory.CreateDatabase("MySql");
<add name="MySql" connectionString="Data Source=YourServerName;Database=YourDataBase;User ID=YourUserID;Password=YourPassword;" providerName="MySql.Data.MySqlClient" />
General
News
Question
Answer
Joke
Rant
Admin
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 7 May 2007 Editor: |
Copyright 2006 by Mark Pryce-Maher Everything else Copyright © CodeProject, 1999-2009 Web17 | Advertise on the Code Project |