Click here to Skip to main content
15,668,126 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi;

i have a vb.net application and i want to make a backup for mysql database from that application by using MySQLDump.

the backup is being constructed successfully but the arabic characters appeared like this 'ط§ظ„ط±ط¦ظٹط³ظٹ'.

is there any way to solve this?

the code:
VB
Try
      Dim backupTime As DateTime = DateTime.Now
      Dim year As Integer = backupTime.Year
      Dim month As Integer = backupTime.Month
      Dim day As Integer = backupTime.Day
      Dim hour As Integer = backupTime.Hour
      Dim minute As Integer = backupTime.Minute
      Dim second As Integer = backupTime.Second
      Dim ms As Integer = backupTime.Millisecond
      Dim tmestr As String = backupTime.ToString()
      Dim file As StreamWriter = New StreamWriter(tmestr)
      Dim proc As ProcessStartInfo = New ProcessStartInfo()
      Dim cmd As String


      tmestr = "C:\\" + year.ToString + "-" + month.ToString + "-" + day.ToString + "-" + hour.ToString + "-" + minute.ToString + ".sql"

      cmd= String.Format("--default-character-set=utf8 --add-drop-database=true -u{0} -p{1} -h{2} --databases {3} {4} {5}| > {6} ", "user", "password", "localhost", "sme_lending", "sme_loans", "sme_collateral", tmestr)

      proc.FileName = "c:\mysqldump.exe"
      proc.RedirectStandardInput = False
      proc.RedirectStandardOutput = True
      proc.Arguments = cmd
      proc.UseShellExecute = False
      Dim p As Process = Process.Start(proc)
      Dim res As String
      res = p.StandardOutput.ReadToEnd()
      file.WriteLine(res)
      p.WaitForExit()
      file.Close()

Catch ex As Exception
      MsgBox(ex.Message)
End Try
Posted
Updated 11-Mar-12 1:05am
v2

1 solution

It depends on the particular console application you are using. It should support one of the Unicode UTFs, but you should check with the documentation.

It could be possible that the utility correctly outputs the text in UTF-8 but does not write the BOM (Byte Order Mark, please see below) which is used by text editors (for example) to know which UTF to use during loading of the text. You can investigate it. The BOM consists of three bytes: 0xEF, 0xBB, 0xBF. (Of course, not in text I've shown below, but in binary form, exactly three bytes.) If BOM is missing, you may want to insert it at the very beginning.

You may want to work without the BOM. You can use text editor having "UTF-8 text without BOM" options or read the text programmatically using, say, the constructor of System.IO.StreamReader with enforced encoding, like this:
C#
using (System.IO.StreamReader reader = new System.IO.StreamReader(fileName, System.Text.Encoding.UTF8))
{
    //read UTF-8-encoded text without BOM here
}


Please see:
http://msdn.microsoft.com/en-us/library/system.io.streamreader.aspx[^],
http://msdn.microsoft.com/en-us/library/system.text.encoding.aspx[^].

About Unicode, UTFs and BOM, please see:
http://en.wikipedia.org/wiki/Unicode[^],
http://unicode.org[^],
http://unicode.org/faq/utf_bom.html[^],
http://en.wikipedia.org/wiki/UTF-8[^],
http://en.wikipedia.org/wiki/Byte_order_mark[^].

—SA
 
Share this answer
 
v6
Comments
Brainy Girl 12-Mar-12 2:34am    
thank you very much its really usefull :)
Sergey Alexandrovich Kryukov 12-Mar-12 3:16am    
You are very welcome.
Good luck, call again.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900