Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all
I used this code for taking mysql back up

try
        {
            DateTime Time = DateTime.Now;
            int year = Time.Year;
            int month = Time.Month;
            int day = Time.Day;
            int hour = Time.Hour;
            int minute = Time.Minute;
            int second = Time.Second;
            int millisecond = Time.Millisecond;

            //Save file to C:\ with the current date as a filename
            string path;
            path = "D:\\MySqlBackup" + year + "-" + month + "-" + day +"-" + hour + "-" + minute + "-" + second + "-" + millisecond + ".sql";
            StreamWriter file = new StreamWriter(path);


            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = "mysqldump";
            psi.RedirectStandardInput = false;
            psi.RedirectStandardOutput = true;
            psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}",
                "root1", "root", "localhost", "schoolmanagement");
            psi.UseShellExecute = false;

            Process process = Process.Start(psi);

            string output;
            output = process.StandardOutput.ReadToEnd();
            file.WriteLine(output);
            process.WaitForExit();
            file.Close();
            process.Close();
}


now here i got exception as
System.ComponentModel.Win32Exception: The system cannot find the file specified at this line(Process process = Process.Start(psi);)


how do i resolve my problem can any one help me please
thanks in advance
Posted
Updated 12-Apr-11 0:31am
v2
Comments
m@dhu 12-Apr-11 6:31am    
wrapped the code.

Two potential problems / causes:
1) You may have permissions problems writing to the root of a disk under Vista/Win7. it is good idea not to rely on storing info there.
2) The system cannot find "mysqldump" as an executable. Make sure it is installed correctly, or specify the full path to the program
 
Share this answer
 
Comments
tulasiram3975 12-Apr-11 7:14am    
Thanks For The Replay,
Sir What I Need to Do Now(itr was installed correctly some times working but not taking
back up it returns 1kb .sql file.
Member 7945810 24-May-11 3:44am    
Thank You very much.Now its working.....
Instead of fetching the data from output and writing to a file, try directing the backup directly to disk (note 4 backslashes):
C#
...
path = "D:\\\\MySqlBackup" + year ...
...
psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3} > {4}",
                "root1", "root", "localhost", "schoolmanagement", path)
...

The output may be extremely large (depending on the database size) so you shouldn't route it through the program unless yo need to interpret it.

Also catch the StandardOutput[^] and StandardError[^] from the process to see if something goes wrong.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900