简体   繁体   English

在c#应用程序中隐藏sqlcmd

[英]Hide sqlcmd in c# application

I am new to c# and I'm rewriting my old batch file script into it but I've come across this problem: 我是c#的新手,我正在将旧的批处理文件脚本改写成它,但我遇到了这个问题:

Basically I want to hide sqlcmd window so I've tried this 基本上我想隐藏sqlcmd窗口所以我试过这个

        Process bkp = new Process();
        bkp.StartInfo.CreateNoWindow = true;
        bkp.StartInfo.UseShellExecute = false;
        bkp.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        bkp = Process.Start("C:\\Program Files (x86)\\Microsoft SQL Server\\90\\Tools\\Binn\\SQLCMD.EXE", "-S This-PC\\MyApp -U user -P pass -Q \"query\"");

But this doesn't work and the black window is still present. 但这不起作用,黑色窗口仍然存在。 Is there a way to really hide it? 有没有办法真正隐藏它?

Thanks 谢谢

You prepared the bkp object but it's not used at all. 你准备了bkp对象,但根本没有使用它。 It gets overwritten at the moment when Process.Start method is called. 它在调用Process.Start方法时被覆盖。

It should look like this: 它应该如下所示:

  Process bkp = new Process();
  bkp.StartInfo.CreateNoWindow = true;
  bkp.StartInfo.UseShellExecute = false;
  bkp.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  bkp.StartInfo.FileName = "C:\\Program Files (x86)\\Microsoft SQL Server\\90\\Tools\\Binn\\SQLCMD.EXE";
  bkp.StartInfo.Arguments = "-S This-PC\\MyApp -U user -P pass -Q \"query\"";
  bkp.Start();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM