Link to home
Start Free TrialLog in
Avatar of humer2000
humer2000

asked on

Restore Mysql database from C# code

Hi Experts,
I'm trying to restore mysql database using C# code
Can someone tell me what wrong in my code or suggest me an apropriate issue
I tried the following and does not work
public static void UnDumpDatabase(string server, string database, string user, string password, string FilePath)
        {
           
            try
            {
                ProcessStartInfo proc = new ProcessStartInfo();
                string args = string.Format(@"-h{0} -u{1} -p{2} {3} < {4}", server, user, password, database, FilePath);
                proc.FileName = ProgramFilesx86() + "\\MySQL\\MySQL Server 5.0\\bin\\mysql.exe";
                proc.Arguments = args;
                proc.CreateNoWindow = true;
                proc.UseShellExecute = false;
                proc.WindowStyle = ProcessWindowStyle.Hidden;
                Process p = Process.Start(proc);
            }
            catch (Exception)
            {

                throw;
            }
        }

Open in new window

Avatar of Roshan Davis
Roshan Davis
Flag of United States of America image

can you replace the Process.Start with the following statements?
using (Process p = Process.Start(proc))
{
    p.WaitForExit();
}

Open in new window

Avatar of humer2000
humer2000

ASKER

It does'nt work ! no database changes and p.exitcode = 1
1. Are you able to do this through command line?
2. Can you make sure the path for the mysql.exe is correct?
It works when i did it through cmd when concatening p.filename and p.arguments
looks like the spaces in the filename may not liking it.
can you put a double quote before and after of proc.FileName?
When I tried to run the code in Console application as the same way i do, it will end up with getting the information of mysql help command (the one we got if we type "mysql --help" in command prompt). Nothing happen at database side, no data is restored and no error is thrown.
What kind of errors did you see?
ASKER CERTIFIED SOLUTION
Avatar of humer2000
humer2000

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial