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. problem in restoring mysql database

problem in restoring mysql database

Scheduled Pinned Locked Moved C#
helpdatabasemysqlsysadmindebugging
11 Posts 5 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.
  • A altafmohd

    sir when i am running this code then process is throwing an exception ....and value of exit code becoming 1 ....i dont know why it is happening so ..plz help me ..

    public void Restore()
    {
    try
    {

                string path;
                path = filetext.Text;
                StreamReader file = new StreamReader(path);
                string input = file.ReadToEnd();
                file.Close();
    
                ProcessStartInfo psi = new ProcessStartInfo();
                psi.FileName = @"C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqlimport";
               // psi.FileName = "mysql";
                psi.RedirectStandardInput = true;
                psi.RedirectStandardOutput = false;
                psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}",userid, paswd, server, comboBox1.Text);
                psi.UseShellExecute = false;
    
               
                Process process = new Process();
                
                //process.StartInfo = psi;
               //process= Process.Start("IExplore.exe");
                   process = Process.Start(psi);
                   //process.WaitForInputIdle();
                 
                       //process.PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
                       process.StandardInput.WriteLine(input);
                       process.StandardInput.Close();
                       process.WaitForExit();
                       process.Close();
                       MessageBox.Show("database is restored");
                   
            }
            catch (IOException ex)
            {
                if (System.Diagnostics.Debugger.IsAttached)
                {
                    Console.WriteLine(ex.ToString()); 
                }
                else
                MessageBox.Show("Error , unable to Restore!");
            }
        }
    
    OriginalGriffO Offline
    OriginalGriffO Offline
    OriginalGriff
    wrote on last edited by
    #2

    What exception? Where? Please, try to give us all relevant information - help us, to help you!

    Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

    "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
    "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

    A 1 Reply Last reply
    0
    • OriginalGriffO OriginalGriff

      What exception? Where? Please, try to give us all relevant information - help us, to help you!

      Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water

      A Offline
      A Offline
      altafmohd
      wrote on last edited by
      #3

      when i am debugging the code and reach to process line and right click at process we find lot of exceptions and first is this .....

      BasePriority = 'process.BasePriority' threw an exception of type 'System.InvalidOperationException'

      L 1 Reply Last reply
      0
      • A altafmohd

        when i am debugging the code and reach to process line and right click at process we find lot of exceptions and first is this .....

        BasePriority = 'process.BasePriority' threw an exception of type 'System.InvalidOperationException'

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #4

        Are you developing on Windows 98?

        MSDN[^] wrote:

        Windows 98 Platform Note: Setting the priority class to AboveNormal or BelowNormal causes an exception to be thrown.

        Bastard Programmer from Hell :suss:

        A 1 Reply Last reply
        0
        • L Lost User

          Are you developing on Windows 98?

          MSDN[^] wrote:

          Windows 98 Platform Note: Setting the priority class to AboveNormal or BelowNormal causes an exception to be thrown.

          Bastard Programmer from Hell :suss:

          A Offline
          A Offline
          altafmohd
          wrote on last edited by
          #5

          no sir i am devloping in windows 7 os

          L 1 Reply Last reply
          0
          • A altafmohd

            no sir i am devloping in windows 7 os

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #6

            In that case, there are two conditions that can cause an InvalidOperationException (according to the documentation)

            The process has exited.

            -or-

            The process has not started, so there is no process ID.

            That's probably why there was an "WaitForInputIdle"; it needs to wait until the process actually started.

            Bastard Programmer from Hell :suss:

            A 1 Reply Last reply
            0
            • L Lost User

              In that case, there are two conditions that can cause an InvalidOperationException (according to the documentation)

              The process has exited.

              -or-

              The process has not started, so there is no process ID.

              That's probably why there was an "WaitForInputIdle"; it needs to wait until the process actually started.

              Bastard Programmer from Hell :suss:

              A Offline
              A Offline
              altafmohd
              wrote on last edited by
              #7

              yes process is exiting actualy its exit code is showing 1.....but i dont know why it is happening which line is to be corected ...so please analyse my code and provide appropriate solution

              L 1 Reply Last reply
              0
              • A altafmohd

                yes process is exiting actualy its exit code is showing 1.....but i dont know why it is happening which line is to be corected ...so please analyse my code and provide appropriate solution

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #8

                altafmohd wrote:

                but i dont know why it is happening which line is to be corected

                Wait until it's done starting before you change it's priority. Take Google and see what "WaitForInputIdle" does, and don't comment lines that are "seemingly" useless.

                altafmohd wrote:

                so please analyse my code and provide appropriate solution

                That's what I have done.

                Bastard Programmer from Hell :suss:

                1 Reply Last reply
                0
                • A altafmohd

                  sir when i am running this code then process is throwing an exception ....and value of exit code becoming 1 ....i dont know why it is happening so ..plz help me ..

                  public void Restore()
                  {
                  try
                  {

                              string path;
                              path = filetext.Text;
                              StreamReader file = new StreamReader(path);
                              string input = file.ReadToEnd();
                              file.Close();
                  
                              ProcessStartInfo psi = new ProcessStartInfo();
                              psi.FileName = @"C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqlimport";
                             // psi.FileName = "mysql";
                              psi.RedirectStandardInput = true;
                              psi.RedirectStandardOutput = false;
                              psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}",userid, paswd, server, comboBox1.Text);
                              psi.UseShellExecute = false;
                  
                             
                              Process process = new Process();
                              
                              //process.StartInfo = psi;
                             //process= Process.Start("IExplore.exe");
                                 process = Process.Start(psi);
                                 //process.WaitForInputIdle();
                               
                                     //process.PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
                                     process.StandardInput.WriteLine(input);
                                     process.StandardInput.Close();
                                     process.WaitForExit();
                                     process.Close();
                                     MessageBox.Show("database is restored");
                                 
                          }
                          catch (IOException ex)
                          {
                              if (System.Diagnostics.Debugger.IsAttached)
                              {
                                  Console.WriteLine(ex.ToString()); 
                              }
                              else
                              MessageBox.Show("Error , unable to Restore!");
                          }
                      }
                  
                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #9

                  altafmohd wrote:

                  catch (IOException ex) { if (System.Diagnostics.Debugger.IsAttached) { Console.WriteLine(ex.ToString()); } else MessageBox.Show("Error , unable to Restore!"); }

                  I object to this catch block: without a debugger, it swallows all available information and leaves no clue as to why the restore failed. Even if your users aren't interested in technical details, you have to support them and will be clueless as soon as the code fails for whatever reason. Write ex.ToString() to the log file! :~

                  Luc Pattyn [My Articles] Nil Volentibus Arduum

                  A 1 Reply Last reply
                  0
                  • L Luc Pattyn

                    altafmohd wrote:

                    catch (IOException ex) { if (System.Diagnostics.Debugger.IsAttached) { Console.WriteLine(ex.ToString()); } else MessageBox.Show("Error , unable to Restore!"); }

                    I object to this catch block: without a debugger, it swallows all available information and leaves no clue as to why the restore failed. Even if your users aren't interested in technical details, you have to support them and will be clueless as soon as the code fails for whatever reason. Write ex.ToString() to the log file! :~

                    Luc Pattyn [My Articles] Nil Volentibus Arduum

                    A Offline
                    A Offline
                    altafmohd
                    wrote on last edited by
                    #10

                    but if i am not writing this in catch block then also same problem is coming ..i just posted this in catch block to check what is the problem in my code ...i dont know much about it ....so see the code is it right ?or what could be the problems

                    1 Reply Last reply
                    0
                    • A altafmohd

                      sir when i am running this code then process is throwing an exception ....and value of exit code becoming 1 ....i dont know why it is happening so ..plz help me ..

                      public void Restore()
                      {
                      try
                      {

                                  string path;
                                  path = filetext.Text;
                                  StreamReader file = new StreamReader(path);
                                  string input = file.ReadToEnd();
                                  file.Close();
                      
                                  ProcessStartInfo psi = new ProcessStartInfo();
                                  psi.FileName = @"C:\\Program Files\\MySQL\\MySQL Server 5.0\\bin\\mysqlimport";
                                 // psi.FileName = "mysql";
                                  psi.RedirectStandardInput = true;
                                  psi.RedirectStandardOutput = false;
                                  psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}",userid, paswd, server, comboBox1.Text);
                                  psi.UseShellExecute = false;
                      
                                 
                                  Process process = new Process();
                                  
                                  //process.StartInfo = psi;
                                 //process= Process.Start("IExplore.exe");
                                     process = Process.Start(psi);
                                     //process.WaitForInputIdle();
                                   
                                         //process.PriorityClass = System.Diagnostics.ProcessPriorityClass.BelowNormal;
                                         process.StandardInput.WriteLine(input);
                                         process.StandardInput.Close();
                                         process.WaitForExit();
                                         process.Close();
                                         MessageBox.Show("database is restored");
                                     
                              }
                              catch (IOException ex)
                              {
                                  if (System.Diagnostics.Debugger.IsAttached)
                                  {
                                      Console.WriteLine(ex.ToString()); 
                                  }
                                  else
                                  MessageBox.Show("Error , unable to Restore!");
                              }
                          }
                      
                      B Offline
                      B Offline
                      Bernhard Hiller
                      wrote on last edited by
                      #11

                      For creating backups of MySQL databases and restoring them, I use the GUI tools. I tried to do it with code of my own, and run into lots of problems: the low quality of the documentation (with your case here: what does exit code/error code/ErrCode 1 mean?), characters outside the 7bit-ASCII range being changed into nonsense, etc. Consequently, I try to avoid MySQL nowadays, even though I was a fan of it in the past. In case you have to stick with MySQL: try to restore the database with the MySQL GUI tools, perhaps you could get some better information there.

                      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