OSQL执行Sql文件

 //执行Sql文件
                                Thread.Sleep(1000);
                                System.Diagnostics.Process pr = new System.Diagnostics.Process();
                                pr.StartInfo.FileName = "osql.exe";
                                pr.StartInfo.Arguments = string.Format(" -U {0} -P {1} -d {2} -s {3} -i \"{4}\"", txtUID.Text.Trim(), txtPWD.Text.Trim(), txtDBNAME.Text.Trim(), txtSERVERNAME.Text.Trim(), @fileName);
                                pr.StartInfo.UseShellExecute = false;
                                pr.StartInfo.RedirectStandardOutput = true;  //重定向输出
                                pr.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;//隐藏输出窗口
                                pr.Start();
                                System.IO.StreamReader sr = pr.StandardOutput;
                                Console.WriteLine(sr.ReadToEnd());
                                pr.WaitForExit();
                                pr.Close();




 string.Format(" -U {0} -P {1} -d {2} -s {3} -i \"{4}\"",用户名,密码,数据库名称, 服务器名称或IP, @fileName);
fileName:sql文件路径
posted @ 2011-06-16 16:07  微米大大  阅读(555)  评论(0编辑  收藏  举报