Backing up Database in MySQL using C#

前端 未结 6 1228
有刺的猬
有刺的猬 2020-12-14 04:06

I created a Winforms in order to backup my Database. Then When I run my program it gives an Win32Exception was unhandled. \"The system cannot find the file specified\" Altho

6条回答
  •  轮回少年
    2020-12-14 05:04

    • Don't putt the whole call inside "path = ", you should use "Arguments" to specify arguments, as name says. If library checks for presence of the called file (your whole path) it shouldn't find it!
    • Are you sure that path is correct? You should find MySQL Server path using registry, not hard-coding the path, or if it can be not easy for you you can pass it as an argument from command line or specify from your form (settings page).
    • You may have missed credentials: -u should be used for username (even if I use --user) and -p should be for password (even if I use --password). Why do you pass "txtBoxDBName.Text" as password?!
    • Maybe your destination path is invalid: it contains spaces, if you use spaces you should use quotes.
    • What does txtBoxDBName.Text (?password?) contains? Spaces too? If yes it doesn't work.
    • Last presence of + @"" is completely useless, it doesn't insert any quotes.

    A correct version of your code with quotes corrected is: path = @"""D:\MySQL\MySQL Server 5.5\bin\mysqldump.exe"" -u " + txtBoxDBUsername.Text + @" -p " + txtBoxDBName.Text + @" > ""D:\C#\Client\Salesmate - EMC\SalesMate\Backup\" + maskeTxtBoxDBFile.Text + @"""";

    For more readability: path = $@"""D:\MySQL\MySQL Server 5.5\bin\mysqldump.exe"" -u {txtBoxDBUsername.Text} -p {txtBoxDBName.Text} > ""D:\C#\Client\Salesmate - EMC\SalesMate\Backup{maskeTxtBoxDBFile.Text}""";

提交回复
热议问题