Ravi Shah
Ravi Shah

Reputation: 873

SQLCMD Mode run with .net windows application

I want to run SQLCMD.EXE through .net windows application how can I achieve this?

Upvotes: 2

Views: 305

Answers (1)

Brave Soul
Brave Soul

Reputation: 3620

you will need to have to use ProcessStartInfo under using System.Diagnostics;

// 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();

Upvotes: 1

Related Questions