المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : backup mysql database using c#



C# Programming
03-14-2012, 10:04 AM
i m providing code which i am running and getting exception plz help in this regard thanx .... http://www.barakasoft.com/script/Forums/Images/smiley_smile.gif




public void Backup()
{
// Process.Start("IExplore.exe");
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 = "C:\\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}",
"root","123456","localhost","userdb");
psi.UseShellExecute = false;

Process process = Process.Start(psi); ///here is exception coming

string output;
output = process.StandardOutput.ReadToEnd();
file.WriteLine(output);
process.WaitForExit();
file.Close();
process.Close();
}
catch (IOException ex)
{
MessageBox.Show("Error , unable to backup!");
}
}





but when i run this code it is providing me runtime eroor exception ........".The system cannot find the file specified " at the line
Process process = Process.Start(psi);