/// <summary>
        /// 导入dmp文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void benImp_Click(object sender, EventArgs e)
        {
            string strExeName = @"imp";
            string strCmdParam = string.Format("{0}/{1}@{2} file={3} full=y ignore=y",_user,_password,_database,path);
            try
            {
                System.Diagnostics.Process proc=new Process();
                proc.StartInfo.FileName = strExeName;
                proc.StartInfo.Arguments = strCmdParam;
                proc.Start();
                //proc.EnableRaisingEvents = true;
                //proc.SynchronizingObject = null;
                proc.WaitForExit();
                proc.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("导入失败!错误信息:\r\n" + ex.Message);
                throw;
            }        }
我没有分配给用户dba权限,使用imp命令是导入不了的,我怎么才能判断数据库导入不了呢,程序怎么改啊?

解决方案 »

  1.   

    System.Diagnostics.ProcessStartInfo ps = new ProcessStartInfo("cmd", "/c "+TextBox2.Text);
    ps.UseShellExecute = false;
    ps.CreateNoWindow = true;
    ps.RedirectStandardOutput = true;
    Process p = Process.Start(ps);string output = p.StandardOutput.ReadToEnd();
    p.WaitForExit();记得里面有一个 stadarderror 你可以查一下
    p.standarderror
      

  2.   

    我明白楼主的意思,你想执行做cmd一样效果执行imp实时返回信息,对吧?
     private  void ExcutCmd(string cmd)
            {
                System.Diagnostics.Process p = new System.Diagnostics.Process();
                p.StartInfo.FileName = "cmd.exe";//需要启动的程序名       
                p.StartInfo.WorkingDirectory = Application.StartupPath;
                p.StartInfo.UseShellExecute = false;
                p.StartInfo.RedirectStandardInput = true;
                p.StartInfo.RedirectStandardOutput = true;
                p.StartInfo.RedirectStandardError = true;
                p.StartInfo.CreateNoWindow = true;
                p.Start();//启动    
               
                p.StandardInput.WriteLine(cmd);            p.BeginOutputReadLine();
                p.StandardInput.WriteLine("exit");
                p.OutputDataReceived += new DataReceivedEventHandler(process_OutputDataReceived);          }
            private  void process_OutputDataReceived(object sender, DataReceivedEventArgs e)
            {
                if (!string.IsNullOrEmpty(e.Data) && !e.Data.Contains(Application.StartupPath))
                    WriMsg(GetIpArea(e.Data) + Environment.NewLine);
            }
            public delegate void WriMsgDelegate(string msg);//定义一个委托
            private  void WriMsg(string msg)//实时写结果到listbox
            {
                if (lsb_evt.InvokeRequired)
                {
                    WriMsgDelegate wmd = new WriMsgDelegate(WriMsg);
                    lsb_evt.Invoke(wmd, new string[] { msg });
                }
                else
                {
                    lsb_evt.HorizontalExtent = Math.Max(lsb_evt.HorizontalExtent, (int)lsb_evt.CreateGraphics().MeasureString(msg.Replace('\n', '\r'), this.lsb_evt.Font).Width + 10);//水平滚动条            
                    bool scroll = false;
                    if (lsb_evt.TopIndex == lsb_evt.Items.Count - (int)(lsb_evt.Height / lsb_evt.ItemHeight))
                        scroll = true;
                    lsb_evt.Items.Add(msg);
                    if (scroll)
                        lsb_evt.TopIndex = lsb_evt.Items.Count - (int)(lsb_evt.Height / lsb_evt.ItemHeight);
                }
               
            }
      

  3.   

    用法:ExcutCmd("cmd下可以执行的命令语句")//这样就可以