SQLCMD 模式 运行 与 .net windows 应用程序

SQLCMD Mode run with .net windows application

我想运行 SQLCMD.EXE 通过.net windows 应用程序如何实现?

您将需要在 using System.Diagnostics;

下使用 ProcessStartInfo
// Calls the sqlcmd
ProcessStartInfo info = new ProcessStartInfo("sqlcmd", @" -S .\sqlexpress -i C:\YourFileName.sql");

//  Indicades if the Operative System shell is used, in this case it is not
info.UseShellExecute = false;

//No new window is required
info.CreateNoWindow = true;

//The windows style will be hidden
info.WindowStyle = ProcessWindowStyle.Hidden;

//The output will be read by the starndar output process
info.RedirectStandardOutput = true;

Process proc = new Process();

proc.StartInfo = info;

//Start the process
proc.Start();