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

LVL 1
humer2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Open in new window

0
humer2000Author Commented:
It does'nt work ! no database changes and p.exitcode = 1
0
Roshan DavisCommented:
1. Are you able to do this through command line?
2. Can you make sure the path for the mysql.exe is correct?
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

humer2000Author Commented:
It works when i did it through cmd when concatening p.filename and p.arguments
0
Roshan DavisCommented:
looks like the spaces in the filename may not liking it.
can you put a double quote before and after of proc.FileName?
0
humer2000Author Commented:
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.
0
tikusbalapCommented:
What kind of errors did you see?
0
humer2000Author Commented:
No error is thrown.
I aborted trying to find solution after hours and days of frustration, and I bought a solution doing the job finely.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.