mySQL Connector for .NET Compact Framework has many bugs. But I found that the following combination can work on WinCE 5.0 with .NET Framework 2.0.
Requirement
1. mySQL Server: 5.1.41
2. mySQL .NET Connector 6.0.6.0 - mysql.data.cf.dll
3. .NET Compact Framework 2.0
4. WinCE 5.0
public class mySQLConnectClass
{
#region Member
private string _pw = "";
private string _user = "user";
private string _database = "";
private string _host = "remotehost";
private string _provider = "";
private MySql.Data.MySqlClient.MySqlConnection myConn = null;
#endregion
#region Properties
public string Password
{
get { return _pw; }
set { _pw = value; }
}
public string User
{
get { return _user; }
set { _user = value; }
}
public string Database
{
get { return _database; }
set { _database = value; }
}
public string Host
{
get { return _host; }
set { _host = value; }
}
public string Provider
{
get { return _provider; }
set { _provider = value; }
}
#endregion
#region Public
public mySQLConnectClass()
{
}
public void Connect()
{
_provider = "Data Source=" + _host + ";Database=" + _database + ";User ID=" + _user + ";Password=" + _pw;
myConn = new MySqlConnection(_provider);
try
{
myConn.Open();
}
catch (Exception ex)
{
throw new Exception(ex.Message.ToString());
}
}
public void Disconnect()
{
string sql = "SELECT name, age FROM table1";
MySqlCommand cmd = new MySqlCommand(sql, myConn);
MySqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
Debug.WriteLine(rdr[0] + " -- " + rdr[1]);
}
rdr.Close();
Debug.WriteLine("Close Reader.");
myConn.Close();
myConn.Dispose();
Debug.WriteLine("Close DB.");
//myConn.Close();
}
public bool Ping()
{
return myConn.Ping();
}
#endregion
#region Private
#endregion
#region Event
#endregion
}