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

مشاهدة النسخة كاملة : how to create database backup programmatically in mysql using c#.net



C# Programming
11-08-2009, 10:00 AM
Hi


I have the code to make the backup of the MySql database like this..

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

String tmestr = backupTime.ToString();
tmestr = "C:\\" + year + "-" + month + "-" + day + "-" + hour + "-" + minute + ".sql";
StreamWriter file = new StreamWriter(tmestr);
ProcessStartInfo proc = new ProcessStartInfo();
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3} > {4};", "root", "password", "localhost", "dbfile", "backup.sql");
proc.FileName = "mysqldump";
proc.RedirectStandardInput = false;
proc.RedirectStandardOutput = true;
proc.Arguments = cmd;//"-u root -p smartdb > testdb.sql";
proc.UseShellExecute = false;
Process p = Process.Start(proc);
string res;
res = p.StandardOutput.ReadToEnd();
file.WriteLine(res);
p.WaitForExit();
file.Close();

}

catch (IOException ex)
{
MessageBox.Show("Disk full or other IO error , unable to backup!");
}
}


while executing the program it is showing an error like
"The system cannot find the file specified" with caption "Win32Exception was unhandled "...

can anyone help in this.....