0

当我尝试进行数据库备份或还原时,意味着它无法正常工作。因为我给出的路径包含“SPACE”

备份/恢复文件路径:“ C:\Documents and Settings\prabhu\Desktop\Backup.sql
Documents and Settings包含“SPACE”)

我在 C# 中工作。

代码:

string directoryName = D:\\Shop Plan\\ERP Project\\Main Source\\OutPut\\Debug\\DBBackup;

string filePath = "C:\Documents and Settings\prabhu\Desktop\Backup.sql";

TextWriter textWriter = new StreamWriter(filePath);

textWriter.WriteLine("CD " + directoryName);

if (type == "Backup")
{
  textWriter.WriteLine("mysqldump -h " + "SERVERNAME"+ " -u " + "USERNAME" + " -p" + "PASSWORD" + " -P " + "PORT" + " --routines " + "DATABASE_NAME" + " -B> " + filePath);
}

else if (type == "Restore")
{
  textWriter.WriteLine("mysql -h " + "SERVERNAME" + " -u " + "USERNAME" + " -p" + "PASSWORD" +" -P " + "PORT" + " <" + filePath);
}

textWriter.Close();

Process processes = new Process();

processes.StartInfo.WorkingDirectory = directoryName ;

processes.StartInfo.FileName = "Backup.BAT";

processes.StartInfo.CreateNoWindow = true;

processes.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;

processes.Start();

processes.WaitForExit();
4

3 回答 3

0
@"C:\Documents and Settings\prabhu\Desktop\Backup.sql"
于 2012-11-20T08:38:40.403 回答
0

你确定是空格吗?也许你需要语法@ http://www.dotnetperls.com/path

于 2012-11-20T08:39:35.667 回答
0

线路:

string directoryName = D:\\Shop Plan\\ERP Project\\Main Source\\OutPut\\Debug\\DBBackup;

string filePath = "C:\Documents and Settings\prabhu\Desktop\Backup.sql";

改成:

string directoryName = "\"" + @"D:\Shop Plan\ERP Project\Main Source\OutPut\Debug\DBBackup" + "\"";

string filePath = "\"" + @"C:\Documents and Settings\prabhu\Desktop\Backup.sql" + "\"";
于 2012-11-20T09:00:24.353 回答