来自vb.net的SQL备份

时间:2016-03-04 15:46:44

标签: mysql vb.net

我使用下面的代码来备份mySQL数据库。我想通过保存文件对话框保存sql数据库。 我用这个,

Sub CreateBackupc()
    Dim mysqldumpPath As String = "C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin\mysqldump.exe"
     Dim host As String = "localhost"
    Dim user As String = "root"
    Dim pswd As String = "mysql"
    Dim dbnm As String = "mcs"
    Dim cmd As String = String.Format("-h{0} -u{1} -p{2} {3}", host, user, pswd, dbnm)
    SaveFileDialog1.Filter = "SQL Files (*.sql*)|*.sql"
    If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK _
    Then
        My.Computer.FileSystem.WriteAllText _
        (SaveFileDialog1.FileName, "mcs.sql", True)
        Dim startInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo()
        startInfo.FileName = mysqldumpPath
        startInfo.Arguments = cmd
        startInfo.RedirectStandardError = True
        startInfo.RedirectStandardInput = False
        startInfo.RedirectStandardOutput = True
        startInfo.UseShellExecute = False
        startInfo.CreateNoWindow = True
        startInfo.ErrorDialog = False
        Dim proc As System.Diagnostics.Process = New System.Diagnostics.Process()
        proc.StartInfo = startInfo
        AddHandler proc.OutputDataReceived, AddressOf OnDataReceivedc
        proc.Start()
        proc.BeginOutputReadLine()
        proc.WaitForExit()
        OutputStreamc.Flush()
        OutputStreamc.Close()
        proc.Close()
    End If
End Sub

但它将richbox文本保存为sql类型文件。我的程序也有富文本框。

0 个答案:

没有答案