0

I am working on a C# application in which I have to make a copy of an already existing database schema in MySQL. I am using mysqldump.exe to accomplish the task. Within a process I execute mysqldump.exe and I pass the required arguments to the process. Below is my process code.

ProcessStartInfo proc = new ProcessStartInfo();
proc.Arguments = @"-h localhost --port 33060 -u root -p1234   MasterDB | mysql -h localhost --port 33060 -u root -p1234 ChildDB";
proc.FileName = @"C:\Program Files\MySQL\MySQL Server 5.6\bin\mysqldump.exe";
proc.UseShellExecute = false;
proc.RedirectStandardOutput = true;
Process p = Process.Start(proc);
using (StreamReader reader = p.StandardOutput)
{
   string result = reader.ReadToEnd();
   Console.Write(result);
}
p.WaitForExit(60000);

When I execute mysqldump.exe from DOS with same arguments it runs fine and make a copy of masterDB schema into childDB. But from within this C# code it doesn't work.

There is some problem with the argument string I am passing to the process. In console application it shows me the error "could not find table". I have tried to make up string different ways but nothing worked for me.

halfer
  • 19,824
  • 17
  • 99
  • 186
umer
  • 1,196
  • 1
  • 14
  • 33

1 Answers1

0

After not finding any answers from anywhere on internet I have worked on my own and find out the solution to my problem. Below is my code which copy my Database Schema A into Database b.

ProcessStartInfo proc = new ProcessStartInfo("cmd.exe");
proc.WorkingDirectory = "C:";
proc.RedirectStandardInput = true;
proc.RedirectStandardOutput = true;
proc.WindowStyle = ProcessWindowStyle.Hidden;
proc.UseShellExecute = false;
proc.CreateNoWindow = true;
Process p = Process.Start(proc);
p.StandardInput.WriteLine(@"cd ""C:\Program Files\MySQL\MySQL Server 5.6\bin""");
p.StandardInput.WriteLine(@"mysqldump -h localhost --port 33060 -u root -p1234 vrecord_client | mysql -h localhost --port 33060 -u root -p1234 "+ DBName +"");
p.WaitForExit();
halfer
  • 19,824
  • 17
  • 99
  • 186
umer
  • 1,196
  • 1
  • 14
  • 33