MySQL Connector for Compact Framework

L

Lonifasiko

Just to let all the group know about MySQL Connector for Compact
Framework 2.0 (version 5.1). You can download if from the following
URL:

http://dev.mysql.com/downloads/connector/net/5.1.html

This download includes a connector for .NET Framework 2.0 (desktop and
web applications) and a connector for Compact Framework applications
that lets you access remote MySQL databases from a CF 2.0 application.
Although CF connector still is under development and being tested,
have to say that MySQL guys are doing a really awesome job.

Therefore, downloaded and installed the connector, created a new
Windows Mobile 5.0 application (should work for WM2003), added a
reference to "MySql.Data.CF.dll" and coded a simple "select
statement". Just one trick (taken from MySQL forums): In the
connection string at the moment must be specified "pooling=false";
otherwise, does not work. So, connection string looks like this:

SERVER=Database server IP
address;DATABASE=databaseName;UID=user;PASSWORD=password;pooling=false

Launched the application in the device and awesome! I'm able to read
records from a remote MySQL database. That's the complete code (don't
forget to add the reference):

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Configuration;

namespace MySQLCompact
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
try
{
lBoxResults.Items.Clear();
MySqlConnection connection = new
MySqlConnection("SERVER=MySQL server IP
address;DATABASE=databaseName;UID=user;PASSWORD=password;pooling=false");
MySqlCommand command = connection.CreateCommand();
MySqlDataReader Reader;
command.CommandText = "select * from table1";
connection.Open();
Reader = command.ExecuteReader();
while (Reader.Read())
{
string thisrow = "";
for (int i = 0; i < Reader.FieldCount; i++)
thisrow += Reader.GetValue(i).ToString() +
",";
lBoxResults.Items.Add(thisrow);
}
connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}

Hope it helps!

Best regards.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top