//执行脚本
string infile = System.Web.HttpContext.Current.Server.MapPath("/Plguin/target/SQLQuery4.sql");
Process sqlprocess = new Process();
sqlprocess.StartInfo.FileName = "osql.exe";
sqlprocess.StartInfo.Arguments = String.Format("-U {0} -P {1} -S {2} -i {3}", " ", " ", " ", @infile); //U为用户名,P为密码,S为目标服务器的ip,infile为数据库脚本所在的路径
sqlprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
sqlprocess.Start();
sqlprocess.WaitForExit(); //等待程序执行.Sql脚本
sqlprocess.Close();