2014-09-04 79 views
-1

我想從Visual Basic中保存一個MySQL數據庫。我的代碼如下。從VB.net調用mysqldump

我收到一條錯誤消息:找不到文件。哪個文件沒有找到,我做錯了什麼?

Private Sub Backup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBackup.Click 

    Dim StrBackup As String 
    Dim strUser As String = "root" 
    Dim strPass As String = "mysql" 
    Dim strDbName As String = "components" 
    Dim strPath As String = "c:\data" 
    Dim newDBName As String = "DataBackup.sql" 

    StrBackup = "C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe --host=localhost --user='" & strUser & "' --password=mysql """ & strDbName & """ -r """ & strPath & newDBName & """" 
    MsgBox(StrBackup) 
    Process.Start(StrBackup) 
+0

那麼這卡給我看的第一件事是,你有與c:\ dataDataBackup.sql連接的strPath&newDBName。你至少需要在那裏添加一個「\」,所以strPath&「\」&newDBName。或者將「\」添加到strPath。 – Capellan 2014-09-04 12:23:46

回答

0

檢查匹配的引號,斜線並確保所有帶空格的值都能正確轉義。例如:

"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe..." 

大概需要是:

"'C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe'..." 

或者更好的使用Process.Start不同過載:

Process.Start("C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe", arguments)