BasePriority ='process.BasePriority'引发了类型异常 'System.InvalidOperationException' ...
这是从我的.net应用程序恢复数据库时遇到的异常..这里我提供代码....
try
{
//Read file from C:\
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 (x86)\MySQL\MySQL Server 5.0\bin\mysqlimport.exe";
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;
Console.WriteLine(psi);
Process process = Process.Start(psi);
process.StandardInput.WriteLine(input);
process.StandardInput.Close();
process.WaitForExit();
process.Close();
MessageBox.Show("database is restored");
}
catch (IOException ex)
{
MessageBox.Show("Error , unable to Restore!");
}
行process.start(psi).
之后。它显示了异常......
Plz提供任何建议......
答案 0 :(得分:0)
当您尝试写入StandardInput
时,看起来该进程尚未启动。
您可以尝试拨打Thread.Sleep()
或WaitForInputIdle()吗?
答案 1 :(得分:0)
尝试此功能它工作正常。只需使用mysql.exe更改mysqlimport.exe。
public static string RestoreDataBase(string ExeLocation,
string Fname,
string DBName,
string Ip,
string Uid,
string Pass)
{
string sql = "";
try
{
//Read file from C:\
string path;
path = Fname;
StreamReader file = new StreamReader(path);
string input = file.ReadToEnd();
file.Close();
ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = ExeLocation;//@"C:\Program Files (x86)\MySQL\MySQL Server 5.0\bin\mysqlimport.exe";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = false;
psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}",
Uid, Pass, Ip, DBName);
psi.UseShellExecute = false;
Console.WriteLine(psi);
Process process = Process.Start(psi);
process.StandardInput.WriteLine(input);
process.StandardInput.Close();
process.WaitForExit();
process.Close();
sql = "OK";
}
catch (Exception ex)
{
sql = ex.Message;
}
return sql;
}
string sql = functionclass.RestoreDataBase(@"C:\Program Files\MySQL\MySQL Server 5.1\bin\mysql.exe", @"C:\iTelBilling-5-4-2013.sql", "iTelBilling", "localhost", "root", "admin");