problem in restoring mysql database
-
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!"); } }
-
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!"); } }
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
-
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
-
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'
-
-
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:
-
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:
-
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
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:
-
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!"); } }
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
-
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
-
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!"); } }
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.