backup problem

nitish

Member
Joined
Mar 14, 2012
Messages
6
Programming Experience
Beginner
there is problem in backup of database.Here i m providing the code..

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 ;
string p = saveFileDialog1.FileName;
path = p + year + "-" + month + "-" + day +
"-" + hour + "-" + minute + "-" + second + "-" + millisecond + ".sql";
StreamWriter file = new StreamWriter(path);


ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = @"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqldump.exe";
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);

string output;
output = process.StandardOutput.ReadToEnd();
file.WriteLine(output);
process.WaitForExit();
file.Close();
process.Close();
MessageBox.Show("backup is created");
}
catch (IOException ex)
{
if (System.Diagnostics.Debugger.IsAttached())
{
Console.WriteLine(ex.ToString());
}
else
MessageBox.Show("Error , unable to backup!");

}

}
so the problem is when pointer reach to this line-
Process process = Process.Start(psi)
then an existing event is automatically called and i dont think that this event has to do anything with it....the event is this..
private void tabControl1_DrawItem(object sender, DrawItemEventArgs e)
{
// if (tabControl1.TabPages.Count != 1)

{
e.Graphics.DrawString("x", e.Font, Brushes.Black, e.Bounds.Right - 15, e.Bounds.Top + 4);
e.Graphics.DrawString(this.tabControl1.TabPages[e.Index].Text, e.Font, Brushes.Black, e.Bounds.Left + 12, e.Bounds.Top + 4);
e.DrawFocusRectangle();
}
}
This event will also be called when backup code will complete.....now it is not going ahead after that that line process.start(psi) ....even is being called as normal routine....and i dont know why after that line code is not executing....
so because of this i m unable to create a proper backup file...so plz give some suggestion asap....
 
Back
Top Bottom