Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide sqlcmd in c# application

Tags:

c#

sqlcmd

I am new to c# and I'm rewriting my old batch file script into it but I've come across this problem:

Basically I want to hide sqlcmd window so I've tried this

        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

like image 283
user2553902 Avatar asked Nov 24 '25 16:11

user2553902


1 Answers

You prepared the bkp object but it's not used at all. It gets overwritten at the moment when Process.Start method is called.

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();
like image 51
nan Avatar answered Nov 27 '25 05:11

nan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!