Cherry City Software
5844 Cinnibar Street SE, Salem, Oregon 97306, USA
Support@CherryCitySoftware.com
Home  
Providers  
Download  
Activation  
Documents  
Feedback  
Login  
 
Introduction

MySQL probably is the most popular open source database server. To learn more about MySQL Database server, please visit MySQL Website.

MySQL library comes with some API's. You may download MySQL Library and its source code from MySQL Website. The MySQL OLE DB Provider is a thin wrapper of those MySQL library Version 5.0 API's. This provider is being implemented with ATL OLE DB Provider templates so that the provider itself has small footprint even though the provider does not have many dependencies. It only depends on MySQL library along with Windows OS runtime. You may use ADO or ADO.NET 2.0 to access data with MySQL OLE DB Provider
Why Do You Need MySQL OLE DB Provider
MySQL OLE DB Provider can be used to access MySQL database in your native code and .NET code as well. It has few dependency and is is very easy to use and very easy to deploy as well.
Most importantly, Cherry City Software MySQL OLE DB Provider is the best OLE DB Provider for MySQL database and it does NOT require you to open your source code.
Features
The following are the features that this MySQL OLE DB Provider supports:
  • Transaction
  • Record scroll
  • Parameters - input and output 
  • Bookmarks
  • Database Schema - tables and their columns
  • Extended error information
  • Multiple queries in one single execution*
  • Transparency - all scripts are transparent to MySQL engine
  • Command Preparation and Column Information on command object
  • IColumnsRowset**
  • Record Add/Delete/Update on the fly**
  • MySQL as linked server in SQL Server 2005**
The current release was tested with MySQL 4.1.x and 5.0 and only support Western European charset.
I am having difficulties to setup the server to support Unicode. If you have any ideas,
please give me your advise.

MySQL TIME is mapped to string. MySQL ENUM, SET and GEOMETRY data types are not supported.

*   - If the SQL statements have parameters, each statement must be executed seperately.
** - Not applicable if MySQL version is 4.1.x or older 
Working with MySQL OLE DB Provider

Using MySQL OLE DB Provider is simple if you have the knowledge of ADO or ADO.NET. The sample code is intended to demostrate how to use MySQL OLE DB Provider. You may find sample code below that demostrate how to use MySQL OLE DB Provider with ADO and ADO.NET. The sample will show you how to use the following features:
  • Transaction
  • Parameter input and output
  • Database schema
  • Record scroll
  • Bookmark

   
//OLEDB connection used throughout this class
private System.Data.OleDb.OleDbConnection m_conn 
            = new System.Data.OleDb.OleDbConnection();   

//On form load, establish an connection to MySQL database
//When a connection is established, enable button to
//allow user populate data
private void Form1_Load(object sender, EventArgs e)
{
    try
    {
        //establish a db connection
        this.m_Read.Enabled = false;
        this.m_SP.Enabled = false;
        m_conn.ConnectionString = @"Provider=OleMySql.MySqlSource.1;"+
            " Data Source=localhost,3306; Initial Catalog=test;" + 
            " User ID=root; Password=MySQL";
        m_conn.Open();
        this.m_Create.Enabled = true;
        
        return;
    }
    catch (System.Data.OleDb.OleDbException ex)
    {
        MessageBox.Show(
            "Failed to open connection to MySQL database. Error Details:"
            + ex.Message);
    }
    catch (System.Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    this.m_Create.Enabled = false;
    this.m_Read.Enabled = false;
}

/// <summary>
/// Find if a table has been created by checking the table schema.
/// </summary>
/// <param name="sTable">sTable is the table name</param>
/// <returns>return true if found, false otherwise</returns>
private bool TableExist(string sTable)
{
    System.Data.DataTable schema = 
        m_conn.GetOleDbSchemaTable(
        System.Data.OleDb.OleDbSchemaGuid.Tables, null);
    foreach (DataRow r in schema.Rows)
    {
        if (r.ItemArray.GetValue(2).ToString().ToLower() == 
            sTable.ToLower() &&
            r.ItemArray.GetValue(3).ToString().ToLower() == "table") 
            return true;

    }
    return false;
}

//Create a test table if it does not exist. If it does exist,
//delete data if any. Then insert data into the test table.
private void m_Create_Click(object sender, EventArgs e)
{
    try
    {
        //create command object
        System.Data.OleDb.OleDbCommand cmd
            = new System.Data.OleDb.OleDbCommand();
        cmd.Connection = m_conn;

        //query string to create table 
        cmd.CommandText = @"CREATE TABLE FieldTest" +
             "(ID INTEGER PRIMARY KEY, Name VARCHAR(20), " +
             "LongDoc MEDIUMTEXT, Image BLOB, Date5 DATE, " +
             "datetime6 DATETIME, time7 TIME, " +
             "timestamp8 TIMESTAMP)";

        //if test has been created, delete all data
        if (this.TableExist("FieldTest"))
            cmd.CommandText = "DELETE FROM FieldTest";
        cmd.ExecuteNonQuery();

        //insert data into FieldTest table
        cmd.CommandText = "INSERT INTO FieldTest " +
            "(ID, Name, LongDoc, Image, Date5, datetime6, Time7, TimeStamp8)"
            + " VALUES (?, ?, ?, ?, ?, ?, ?, ?);";
        System.Data.OleDb.OleDbParameter[] oParams
            = new System.Data.OleDb.OleDbParameter[8];
        for (int i = 0; i < 8; i++)
        {
            oParams[i] = new System.Data.OleDb.OleDbParameter();
            cmd.Parameters.Add(oParams[i]);
        }

        
        //start transaction
        System.Data.OleDb.OleDbTransaction tran
            = m_conn.BeginTransaction(); 
        cmd.Transaction = tran;
        byte[] ba = new byte[1000]; 
        for (int i = 0; i < 260; i++)
        {
            oParams[0].Value = 100 + i;
            oParams[0].DbType = DbType.Int32;
            oParams[1].Value = "MyName " + i.ToString();
            oParams[2].Value = "A long long long long long long text";
            ba[i] = (byte)i;
            oParams[3].Value = ba;
            oParams[4].Value = System.DateTime.Now - new TimeSpan(i, 0, 0, 0);
            oParams[4].DbType = DbType.Date;
            oParams[5].Value = System.DateTime.Now
               - new TimeSpan(i, i % 24, i % 60, i % 60);
            oParams[5].DbType = DbType.DateTime;
            oParams[6].Value = new TimeSpan(i % 24, i % 60, i % 60);
            oParams[6].DbType = DbType.Time;
            oParams[7].Value = System.DateTime.Now;
            oParams[7].DbType = DbType.DateTime;
            cmd.ExecuteNonQuery();
        }
        //at last commit transaction
        tran.Commit();

        //test all time related fields
        DateTimeTest();
        
        MessageBox.Show("Done");
        m_Read.Enabled = true;
        m_SP.Enabled = true;
    }
    catch (System.Data.OleDb.OleDbException ex)
    {
        MessageBox.Show(ex.Message);
    }
    catch (System.Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    
}

 //Test date and time related data types
private void DateTimeTest()
{
    System.Data.OleDb.OleDbCommand cmd = 
        new System.Data.OleDb.OleDbCommand();
    cmd.Connection = m_conn;
    if (!this.TableExist("TimeTest"))
    {
        cmd.CommandText = 
            "CREATE TABLE TimeTest (date0 DATE, time1 TIME," + 
            " dateTime2 DATETIME, ts3 TIMESTAMP)";
    }
    else
    {
        cmd.CommandText = "delete from timeTest";
    }
    cmd.ExecuteNonQuery();

    System.Data.OleDb.OleDbParameter[] oParams = 
        new System.Data.OleDb.OleDbParameter[4];
    for (int i = 0; i < 4; i++)
    {
        oParams[i] = new System.Data.OleDb.OleDbParameter();
        oParams[i].Value = DateTime.Now;
        cmd.Parameters.Add(oParams[i]);
    }
    oParams[0].DbType = DbType.Date;
    oParams[1].Value = new TimeSpan(-80, 6, 2);
    oParams[1].DbType = DbType.Time;
    oParams[2].DbType = DbType.DateTime;
    oParams[3].DbType = DbType.DateTime;
    cmd.CommandText =
        "INSERT INTO TimeTest (date0, time1, dateTime2, ts3) values (?,?,?,?)";
    cmd.ExecuteNonQuery();

}
/// <summary>
/// Create an stored procedure and test input and output parameters
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void m_SP_Click(object sender, EventArgs e)
{
    try
    {
        //Create a stored procedure
        System.Data.OleDb.OleDbCommand cmd =
            new System.Data.OleDb.OleDbCommand();
        cmd.CommandText =
            "DROP PROCEDURE IF EXISTS MyProc;CREATE PROCEDURE MyProc" +
            " (param INT, OUT param1 INT, OUT Param2 DATE, OUT param3" + 
            " DATETIME, OUT param4 TIME) BEGIN SET param1 = param*param;" + 
            " SET param2='2000-10-10', param3='2001-12-31 01:02:03'," +
            " param4='9:8:7'; END;";
        cmd.Connection = m_conn;
        cmd.ExecuteNonQuery();

        //call stored procedure with input and output parameters
        cmd.CommandText = "call MyProc(?, ?, ?, ?, ?)";

        System.Data.OleDb.OleDbParameter[] oParams = 
            new System.Data.OleDb.OleDbParameter[5];
        for (int i = 0; i < 5; i++)
        {
            oParams[i] = new System.Data.OleDb.OleDbParameter();
            oParams[i].Direction = ParameterDirection.Output;
            cmd.Parameters.Add(oParams[i]);
        }

        //setup input parameters
        oParams[0].Value = 10;
        oParams[0].DbType = DbType.Int32;
        oParams[0].Direction = ParameterDirection.Input;

        //setup output parameter types
        oParams[1].DbType = DbType.Int32;
        oParams[2].DbType = DbType.Date;
        oParams[3].DbType = DbType.DateTime;
        oParams[4].DbType  = DbType.Time;

        cmd.ExecuteNonQuery();
        
        //run debug to view output values
        System.Diagnostics.Debug.WriteLine(oParams[1].Value.ToString());
        System.Diagnostics.Debug.WriteLine(oParams[2].Value.ToString());
        System.Diagnostics.Debug.WriteLine(oParams[3].Value.ToString());
        System.Diagnostics.Debug.WriteLine(oParams[4].Value.ToString());

        MessageBox.Show("Done");
    }
    catch (System.Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    
}

/// <summary>
/// read data back from a FieldTest table and present it on a data grid
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void m_Read_Click(object sender, EventArgs e)
{
    try
    {

        System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand();
        cmd.Connection = m_conn;
        cmd.CommandText = "select * from FieldTest";
        System.Data.OleDb.OleDbDataAdapter da =
            new System.Data.OleDb.OleDbDataAdapter();
        da.SelectCommand = cmd;
        DataTable dt = new DataTable();
        da.Fill(dt);
        HexDecBinding.Util.SetupGVColumns(m_DGVResult, dt);
        this.m_DGVResult.DataSource = dt;
    }
    catch (System.Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
    
}
                   
                
Using MySQL OLE DB Provider in Visual Studio 2005 IDE
Using MySQL OLE DB Provider with Visual Studio 2005 IDE is very handy. You can readily add MySQL OLE DB Provider into Visual Studio 2005 IDE by adding Data connections via the OLE DB provider.
Using MySQL OLE DB Provider with SQL Server DTS
Refer to Using MySQL Provider to transfer MySQL data into SQL Server.
Activation
MySQL OLE DB Provider must be activated before you can use it. To activate it, you must download the provider and get your passcode from the Activator included in the package. Click here to get activation code.
Download
Update History:
DateChanges
2008-05-18Implemented IRowsetChange and IColumnsRowset interfaces so that the provider can support Linked Server and .NET dynamic Insert/Delete/Update commands. Features avialable in Beta release.
2008-04-10Fixed a bookmark issue introduced in the previous beta release on 3/15/2008
2008-03-15Fixed a parameter binding issue with non-English characters. Added backward compatibility for table schema. Fixed Column schema information for MySQL 5.+
2007-01-20Unlocked all features as long as it is activated; Fixed an activation defect; Improved performances.
2006-10-04Implemented schema rowsets for catalogs and views, ICommandPrepare interface, GetColumnInfo on command, and IDBInfo interface as well.
2006-09-16Integrated with MySQL library 5.0.24a.
2006-05-08Fixed an issue on MySQL datetime to MS datetime conversion.
2006-03-05Fixed a critical activation bug.
2006-01-02Upgraded to support stored procedure calls with in/out parameters.
2005-11-27Upgraded to support ADO.NET 2.0.
2005-11-20Added default port number if missing from connection string.
2005-07-07Intial Release.

MySQL OLE DB Provider (Beta)
MySQL OLE DB Provider
Provider VB Test source
C# Sample source code
Disclaim
This whole post here including the downloads is provided 'as-is', without any express or implied warranty. In no event will the author be held liable for any damages arising from the use of this software.
Feedback
To send me feedback, click here

Copyright © Cherry City Software, LLC. 2006 - 2008