Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. backup

backup

Scheduled Pinned Locked Moved C#
databasehelpmysqlgraphicssysadmin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    nitish_07
    wrote on last edited by
    #1

    Hi...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) { 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.Bo
    
    L 1 Reply Last reply
    0
    • N nitish_07

      Hi...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) { 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.Bo
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      The event has nothing to do with it as you stated; it merely redraws a tabitem. You're catching the output of the application that you're starting.

      string output;
      output = process.StandardOutput.ReadToEnd();

      What does the string "output" contain?

      catch (IOException ex)
      {
      MessageBox.Show("Error , unable to backup!");
      }

      Does it show this message? Can you check whether the code throws an exception? Change the errorhandler to something similar like below;

      catch (IOException ex)
      {
      if (System.Diagnostics.Debugger.IsAttached())
      {
      Console.WriteLine(ex.ToString()); // paste the info that's shown here into your post
      }
      else
      MessageBox.Show("Error , unable to backup!");
      }

      Bastard Programmer from Hell :suss:

      N 1 Reply Last reply
      0
      • L Lost User

        The event has nothing to do with it as you stated; it merely redraws a tabitem. You're catching the output of the application that you're starting.

        string output;
        output = process.StandardOutput.ReadToEnd();

        What does the string "output" contain?

        catch (IOException ex)
        {
        MessageBox.Show("Error , unable to backup!");
        }

        Does it show this message? Can you check whether the code throws an exception? Change the errorhandler to something similar like below;

        catch (IOException ex)
        {
        if (System.Diagnostics.Debugger.IsAttached())
        {
        Console.WriteLine(ex.ToString()); // paste the info that's shown here into your post
        }
        else
        MessageBox.Show("Error , unable to backup!");
        }

        Bastard Programmer from Hell :suss:

        N Offline
        N Offline
        nitish_07
        wrote on last edited by
        #3

        Sir as u said i have pasted that code but the same thing is happening again.Again after that line code goes to that event dont know why....and one more think backfile is being created but there is nothing in the backup file because after that line code is not executing.....:(

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups