string infile = System.Web.HttpContext.Current.Server.MapPath("test.sql");
Process sqlprocess = new Process();
sqlprocess.StartInfo.FileName = "osql.exe";
sqlprocess.StartInfo.Arguments = String.Format("-U {0} -P {1} -S {2} -d {3} -i {4}", "sa", "1234567890", "(local)", "Lottery", @infile);
//("-U {0} -P {1} -S {2} -i {3}", "kkuu", "123456", "localhost", @infile); //建库
//U为用户名,P为密码,S为目标服务器的ip d 数据名, infile为数据库脚本所在的路径
sqlprocess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
sqlprocess.StartInfo.UseShellExecute = false;
sqlprocess.StartInfo.CreateNoWindow = true;
sqlprocess.StartInfo.RedirectStandardOutput = true;
sqlprocess.StartInfo.RedirectStandardError = true;
sqlprocess.Start();
string str = sqlprocess.StandardOutput.ReadToEnd();
sqlprocess.WaitForExit();
//等待程序执行.Sql脚本
sqlprocess.Close();
StreamWriter sw = new StreamWriter(Server.MapPath("RunSqlLog.txt"), true, System.Text.Encoding.UTF8);
sw.Write(str);
sw.Close();
show.Text = str+"<br> 操作完毕。";
aspx 执行sql语句(Process)
最新推荐文章于 2022-07-11 07:34:00 发布