Page 1 of 1

Dump Example error

Posted: Fri 14 Oct 2005 11:28
by Johnny Lung
VS:2003 and CoreLab.MySql:2.80.9.0

When using C# dump example come with CoreLab installer, I tried to backup an MySQL 4.0 DB in Traditional Chinese and save the file. The file give text like:
Image

The DB table charset is utf8 and InnoDB.

What code should I modify to have correct text?

Backup function:

Code: Select all

    private void btBackup_Click(object sender, System.EventArgs e) {
      StringBuilder Tables = new StringBuilder();

      foreach (String str in lbSelected.Items)
        Tables.AppendFormat("`{0}`;",str);
      
      mySqlDump.Tables = Tables.ToString();
      statusBar.Panels[0].Text = "Backup in progress";
      mySqlDump.Backup();
      statusBar.Panels[0].Text = "Backup complete";
    }
Save function:

Code: Select all

    private void btSave_Click(object sender, System.EventArgs e) {
      if (saveFileDialog.ShowDialog() == DialogResult.OK) {
        Stream stream = saveFileDialog.OpenFile();
        if (stream != null) {
          statusBar.Panels[0].Text = "Save in progress";
          Encoding unicodeString = Encoding.Unicode;
          stream.Write( unicodeString.GetBytes(mySqlDump.DumpText), 0, unicodeString.GetBytes(mySqlDump.DumpText).Length);
          stream.Close();
          statusBar.Panels[0].Text = "Save complete";
        }
      }
    }
Thanks

Posted: Fri 14 Oct 2005 12:39
by Serious
To use UTF-8 character set please set MySqlConnection.Unicode = true.
For additional information refer to this property documentation.