{“The directory name is invalid”} Win32Exception Was unhandled

妖精的绣舞 提交于 2020-01-04 02:48:09

问题


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;  

    }

got an exception at this line sd = Process.Start(r1);

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

would any one pls help me guys

Many thanks In advance..

Modified 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 ..


回答1:


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", ...

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\", ...

Update 1

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

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

Update 2

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.



来源:https://stackoverflow.com/questions/7686945/the-directory-name-is-invalid-win32exception-was-unhandled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!