我引用李洪根的.NET平台下WEB应用程序的部署(安装数据库和自动配置)里的osql执行方法,但是不能执行.sql里的语句,郁闷中........
  求用osql执行.sql的代码或实例,和一些注意事项,麻烦各位了.!!!!!!!!!

解决方案 »

  1.   

    private void CreateDataBase ()
    {
    Process p = new Process(); 
    p.StartInfo.FileName = "cmd.exe"; 
    p.StartInfo.UseShellExecute = false; 
    p.StartInfo.RedirectStandardInput = true; 
    p.StartInfo.RedirectStandardOutput = false; 
    p.StartInfo.RedirectStandardError = true; 
    p.StartInfo.CreateNoWindow = true; 
    string Path = Application.StartupPath.ToString();
    string Parameter = "osql.exe -U " + uid + " -P " + pwd + " -S  "+ ServerName +" -i " + Path + @"\IPMS.sql";
    try 

    this.Cursor = System.Windows.Forms.Cursors.WaitCursor;
    p.Start(); 
    p.StandardInput.WriteLine(Parameter); 
    p.StandardInput.WriteLine("exit"); 
    p.StandardInput.WriteLine("exit");
    p.WaitForExit(); 
    p.Close();

    catch(Exception e) 

    MessageBox.Show(e.Message);
    this.Close();

    }