{"该目录名无效"} Win32Exception了未处理 [英] {"The directory name is invalid"} Win32Exception Was unhandled

查看:284
本文介绍了{"该目录名无效"} Win32Exception了未处理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想备份用mysql和C#数据库 通过下面的方法...

I am trying to backup the database using mysql and c# by using following way...

  public static  void backupDatabase()
    {
        Process sd = null;
        ProcessStartInfo r1 = new ProcessStartInfo("C:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\", "--databases=access --compress --routines --triggers --add-drop-database --add-drop-table --add-locks --extended-insert --port=3080 --user=root --disable-keys --quick --comments --complete-insert --result-file=DUMPEDOUTPUT.sql");

        r1.CreateNoWindow = true;
        r1.WorkingDirectory = "C:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\";
        r1.UseShellExecute = false;
        r1.WindowStyle = ProcessWindowStyle.Minimized;
        r1.RedirectStandardInput = false;

        sd = Process.Start(r1);
         sd.WaitForExit();

        if (!sd.HasExited)
        {
             sd.Close();
        }
        sd.Dispose();
         r1 = null;
         sd = null;  

    }

在这一行有一个例外 SD =的Process.Start(R1);

Exception :{"The directory name is invalid"}   Win32Exception Was unhandled

会不会有人请帮助我的家伙

would any one pls help me guys

提前很多感谢。

修改code:

  public static  void backupDatabase()
    {
        Process sd = null;
        ProcessStartInfo r1 = new ProcessStartInfo("MySQLWorkbench.exe", "--databases access --compress --routines --triggers --add-drop-database --add-drop-table --add-locks --extended-insert --port=3080 --user=root --disable-keys --quick --comments --complete-insert --result-file=DUMPEDOUTPUT.sql");

        r1.CreateNoWindow = true;
        r1.WorkingDirectory = @"C:\Program Files\MySQL\MySQL Workbench 5.2 CE\MySQLWorkbench.exe";
        r1.UseShellExecute = false;
        r1.WindowStyle = ProcessWindowStyle.Minimized;
        r1.RedirectStandardInput = false;

        sd = Process.Start(r1);
         sd.WaitForExit();

        if (!sd.HasExited)
        {
             sd.Close();
        }
        sd.Dispose();
         r1 = null;
         sd = null;  

    }

我在同一行得到同样的错误。

I am getting same error at the same line ..

推荐答案

在第一个参数的 的ProcessStartInfo 应该是要运行的可执行文件。现在,你已经将其指向的目录

The first parameter to the ProcessStartInfo should be the executable you want to run. Right now you have it pointing to a directory

new ProcessStartInfo("C:\\Program Files\\MySQL\\MySQL Workbench 5.2 CE\\", ...

这可能应该是

It should probably be

new ProcessStartInfo(
   @"C:\Program Files\MySQL\MySQL Workbench 5.2 CE\MySQLWorkbench.exe", ...

您也可以通过在字符串前面使用 @ 所以你不需要逃脱反斜杠specifiy的路径名。像这样的:

You can also specifiy the path name by using @ in front of the string so you dont need to escape the backslashes. Like this:

new ProcessStartInfo(@"C:\Program Files\MySQL\MySQL Workbench 5.2 CE\", ...

更新1

另一件事尝试,因为你已经指定的工作目录,只是把可执行文件名中的的ProcessStartInfo

Another thing to try, since you already specify the working directory, just put the executable name in the ProcessStartInfo

new ProcessStartInfo("MySQLWorkbench.exe", ...

更新2

只注意到你添加的EXE文件名的 WorkingDirectory 。这应该只是目录:

Just noticed you added the exe filename to the WorkingDirectory. This should just be the directory:

Process sd = null;
ProcessStartInfo r1 = new ProcessStartInfo("MySQLWorkbench.exe", ...);

r1.CreateNoWindow = true;
r1.WorkingDirectory = @"C:\Program Files\MySQL\MySQL Workbench 5.2 CE";

不过,我认为这个问题是可能的权限。我的猜测是当前用户不必须的权限来此文件的路径。

But I think the issue is probably the permissions. My guess is the current user doesnt have permissions to this file path.

这篇关于{"该目录名无效"} Win32Exception了未处理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆